Parsley Index

This index collects all Parsley syntax and methods.


When looping through a content model with an each loop, you can use variable_name._index to get the current count of how many times you have run through the each loop. _index begins counting from 0. To start counting at 1 use _num instead.

<div class="row">
{{ each team_members as member }}
{{ if {member._index} % 3 == 0 }} (** Checks for every third loop, can be used to end and stop rows when using fixed width columns in a grid **)
</div><div class="row">
{{ end-if }}
<div class="column">
<p>{{ }}</p>
<p>{{ member._index }}</p>
{{ end-each }}


When looping through a content model with an each loop, you can call {{ variable_name._length }} to get the total number of times the loop will run.

<div class="article-tags">
{{ each article_tag as tag }}
<p>{{ }}{{ if {tag._num} != {tag._length} }}, {{ end-if }}</p>
{{ end-each }}
(** As long as the loop's num does not equal its length a comma will be appended to the list of tags **)


When looping through a content model with an each loop, you can use variable_name._num to get the current count of how many times you have run through the each loop. _num begins counting from 1. To start counting at 0 use _index instead.

<div class="article-tags">
{{ each article_tag as tag }}
<p>{{if {tag._num} == 1 }}This is the first item{{ end-if }}</p>
{{ end-each }}
(** As long as the loop's num does not equal its length a comma will be appended to the list of tags **)


Converts plain text URLS into anchor tags URL. Useful for content where text comes in with HTML stripped.

{{ page.textarea.activate_links() }}


{{ each api.dribbble.getShots(USER_NAME) as shot }}
<img src="{{ shot.image_teaser_url }}" alt="{{ shot.title} }" />
{{ end-each }}


The breadcrumbs call outputs an automated breadcrumb trail of links, listing the parent pages assigned to the current page. If there are no available links, then an empty span is outputted.

{{ breadcrumbs }}
Example Output:
<span itemprop="breadcrumb">
<span class="crumb"><a href="/blog/">Blog</a></span>
<span class="sep">»</span>
<span class="crumb"><a href="/blog/example-category/">Example Category</a></span>
<span class="sep">»</span>
<span class="crumb">Example Post</span>

clippings (see Globals)

Comments (** **)

Use these comments to prevent Parsley or other code from processing in HTML and Endpoint files. Anything within these comments are server side comments and will not render out to the source code.

(** old code **)
< h1>{{ page.title }}</h1>
(** new code **)
<h3>{{ page.new_title }}</h3>


The {{ current_view }} call is a unique statement that will load the Page View associated with the current website url. {{ current_view }} is used once in the loader snippet. This allows a website to have consistent template elements above and below the unique aspect of each page.

{{ include header }}
<div class="content">
{{ current_view }}
{{ include footer }}


Uses the php date format to create the date string shown to the user.

<em>{{, F jS, Y \a\t g:ia) }}</em>
// <em>Sunday, January 1st, 2011 at 10:50pm</em>


This method creates an expression of duration comparing the date and time from a content field to the current date and time.

{{ }}
[x time] ago


The Parsley Each statements, also known as loops, allow you to iterate (loop) through each entry of a content model.

{{ each team_members as member }}
<p>{{ }}</p>
{{ end-each }}


The else statement allows for a a final case if none of the defined conditions in the if statement have been met.

{{ if {page.field} == 1 }}
Example where first condition is met
{{ else-if {page.field} == 2 }}
Example where second condition is met
{{ else }}
Example where no condition is met
{{ end-if }}


The else-if statement is used for the defining alternate conditions, if the original if condition is not met. There can be as many else-if statements as needed after the opening if statement and before the end-if.

{{ if {page.field} == 1 }}
Example where first condition is met
{{ else-if {page.field} == 2 }}
Example where second condition is met
{{ else }}
Example where no condition is met
{{ end-if }}


Required to close each loops.

{{ each team_members as member }}
<p>{{ }}</p>
{{ end-each }}


Required to close an if statement.

{{ if {page.field} == 1 }}
Example where first condition is met
{{ else-if {page.field} == 2 }}
Example where second condition is met
{{ else }}
Example where no condition is met
{{ end-if }}


The escapeForJs() call returns text with all the characters that could break a Javascript or JSON string escaped with \.

"title": "{{ page.title.escapeForJs() }}"


The .filter() call can be used to access specific data based on the scope.

{{ scope.filter(z.zuid = '{}').scope-field }}
{{ another-set.filter(z.zuid = '{}').page_title }}


The find_in_set query allows for looking for a specific number or string in a comma separated list. find_in_set is always used to filter a Content Model related with a One-to_Many relational field.

{{ each tags as tag where find_in_set(tag.zuid, '{this.tags}') }}
<span>{{ tag.title }}</span>
{{ end-each }}


The first() call will access the content available in the first entry of any content model.

{{ content_model.first().title }}
// "This is the title for the first entry of a content model"


The format_currency() call transforms a float number from a content field to the format $XX.XX.

{{ each products as product }}
{{ product.price.format_currency() }}
{{ end-each }}


The get_var call returns the value of any query parameter in the current URL by referencing the key. When printing out any query parameter using get_var, be sure to use htmlentities() to prevent Cross-site Scripts and code injections.

// at the page /blog/?category=news
{{ get_var.category.htmlentities() }}


Every content model in Zesty (single page, page groups or datasets) can access a public RSS feed. It will always be content_model_refrence_name-feed.rss/

{{ content_model.getfeedurl() }}

getImage(width, height, type)

The getImage() function takes optional arguments for width, height, and type (fit or crop) and returns a URL to that image. Fit is the default and does not need to be explicitly declared. Crop type requires all 3 arguments declared. Fit is similar to the css style "contain" and crop is similar to the css style "cover".

<img src="{{ }}" />
<img src="{{ }}" />
<img src="{{,100,fit) }}" />
<img src="{{,,fit) }}" />
<img src="{{,100,fit) }}" />
<img src="{{,100,crop) }}" />


The `getImageTitle() call returns the image title set in the Media Tab.

{{ page.image.getImageTitle() }}


The getMediaURL() call returns the original URL to that file. This is how to access files stored in the Media Tab that are not images, such as PDFs and MP4s. You can also use this call to access the original file of an image without the default optimization provided by

<a href="{{ page.download_file.getMediaURL() }}" >Download</a>
// <a href="" >Download</a>
// If looping through an image field with multiple images use this call
{{ my-var.image.getmediaurl() }}


The getNextURL() call returns the current page url with a query parameter p increased by the number specified. If there is no query parameter p, it will set it equal to the number specified. If no number is provided, the default is 5. This can be used with get_var.p to do pagination with an each loop.

{{ page.getNextURL(10) }}
// blog/?p=10


The getPreviousURL() call returns the current page url with a query parameter p decreased by the number specified. If there is no query parameter p, it will set it equal to 0. If no number is provided as an argument, the default is 5. This can be used with get_var.p to do pagination with an each loop.

// on the page /blog/?p=30
{{ page.getpreviousurl(10) }}
// /blog/?p=20


The getUrl() call returns the relative path to the entry.

<a href="{{ blog.first().getUrl() }}">Link</a>
// <a href="/blog/">Link</a>


The globals call is used to access content stored in the Globals (formerly Content Clippings) set.

{{ }}
// Returns:

Google Analytics

Parsley provides a short cut to creating google analytics tag. The advantage of using this Parsley call is that as Google Analytics updates their syntax, it will be automatically updated on your website.

This call {{gaEvent(eventCategory,eventAction,eventLabel,eventValue)}} will trigger an event to your Google Analytics integration.

eventCategory: text required Typically the object that was interacted with (e.g. 'Video')

eventAction:text required The type of interaction (e.g. 'play')

eventLabel:*text* optional Useful for categorizing events (e.g. 'Fall Campaign')

eventValue:*integer* optional A numeric value associated with the event (e.g. 42)

Read the spec for GA Events here

<pre><a href="" {{gaEvent(Vimeo, Opened-video)}}>My Video</a></pre>
// returns
<pre><a href="" onclick="ga('send','event', 'Vimeo', ' Opened-video', ' ',undefined,'{'nonInteraction': 1}');">My Video</a></pre>


The gravatar() function takes an email address and requests an image from the Gravatar API.

"<img class="highlight" src="{{ page.author_email.gravatar() }}" />"
// <img class="highlight" src="" />


The hasChildren() function returns true or false, depending if any pages are parented to the entry. This can be used to find out if a page has pages that live under it. This is helpful when using logic to create secondary navigations.

{{ if {page.hasChildren()} }}
// subnav code
{{ end-if }}


The html_entity_decode call converts all HTML entities in the provided string to their applicable characters.

<p>{{ page.description.html_entity_decode() }}</p>


The htmlentities() call convert all applicable characters to HTML entities. Should be used whenever printing out a get or post variable to prevent Cross-site Scripting and code injection.

{{ }}


The if statement evaluates conditions using ==, !=, >=, <=, <, and >. Within the if statement, multiple conditions can be combined using && for and, and || for or. If statements can also execute math.

{{ if {page.field} == 1 && {page.price} + 10 > 100 }}
{{ end-if }}


The include call is a prompt to reference the code in any View which includes views, snippets, and endpoints.

{{ include header }}


The last() call will access the content available in the last entry of any content model.

{{ articles.last().title }}


The limit statement is used in an each loop to specify how many content entries will result. The limit statement can also be used to skip a number of entries and show the next set if two arguments are provided.

{{ each articles as post where post.featured = 1 sort by desc limit 20 }}
// entries 1 through 20
{{ end-each }}
{{ each articles as post where post.featured = 1 sort by desc limit 10,20 }}
// entries 11 through 30
{{ end-each }}

math( statement )

The math() call executes an equation and returns a number.

(** plain output **)
{{ math( 1 + 2 ) }}
(** in use with a page field **)
{{ math( round({page.product_cost} * 1.5) ) }}
(** in use with a variable **)
{{ $my_num = 4 }}
{{ math( {$my_num} + 2 ) }}


The navigation() call will access your Navigation Structure and output it as an HTML list. The call will mimic the content navigation layout you find in the Content Manager and will ignore pages marked as unlisted. A number argument will specify what level of children to access within the navigation. Blank will list all pages, 1 will only be top level pages, 2 will be top level and subpages, 3 will be top level, subpages and tertiary pages, and so on.

{{ navigation() }}
// Returns:
<ul id="nav" class="nav">
<li><a href="..."></a>
<li><a href="..."></a></li>
<li><a href="..."></a></li>


The number_format() call returns a number with the specified number of decimals as the argument. Blank will remove any decimals.

{{ $number = 3.14 }}
{{ $number.number_fomat(1) }}
// Returns:


The obfuscate() call returns obscure text to web crawlers, like email or phone numbers.

<a href="mailto:{{}}">{{}}</a>


The page call represents the content entry for the current page. It provides access to the data associated with the page. Any field in the Content Model can be accessed using this method when on the associated page.

{{ page.field_name }}

paypalStandard(action, product, price, shipping)

Quickly create a Paypal Standard buy, donate, or add to cart button in Parsley. To start using Paypal Standard a Paypal account must be created. The Paypal account information and tax rate are set in the Config Tab, under Settings-> Paypal Standard. These must be set to send money to the appropriate account. Action can be buy, addtocart and donate.

{{ each products as p }}
<h1>{{ p.title }}</h1>
<p>{{ p.price }}</p>
{{ paypalStandard(buy,{p.title},{p.price},{p.shipping}) }}
{{ end-each }}


The post_clean() call replaces \n \r\n or \ with a blank string.

{{ page.imported_content.post_clean() }}


The post_var call references data available in the requests post body. A couple common ways data can be added to the request post body is by submitting a form with a method="post" or using javascript POST. A common practical use for this call is to check is a form has been submitted by checking if the POST variable for the name of a required input is available.

{{ if {} }}
Thank you for submitting your form, please check {{ }} for a verification email.
{{ else }}
// form code
{{ end-if }}

preg_replace(pattern, replacement)

The preg_replace() call is a regular expression replacement. To learn more about Regular expression go to

{{ page.content.preg_replace(/i/,*) }}
I'm gonna f*x that last joke by tak*ng out all the words and add*ng new ones.
- M*tch Hedberg


The random() call is used to reference a random content entry for a content model.

{{ articles.random().title }}
// "the 'title' from a random item in 'articles'"

replace(pattern, replacement)

The replace() call does a simple replace without any regular expression.

// $description = "We wrote this blog post"
{{ $description.replace('We', 'I') }}
// "I wrote this blog post"


Get the full path from request, for example lets use the url /store/12345/my-product/

{{ request.path() }} // output: /store/12345/my-product/


Get the "parts" of a url, for example lets use the url /store/12345/my-product/

{{ request.pathPart(1) }} // output: store
{{ request.pathPart(2) }} // output: 12345
{{ request.pathPart(3) }} // output: my-product
{{ request.pathPart(4) }} // output: (empty string)


Get the query parameters from url, for example lets use the url /store/12345/my-product/?test=hello

{{ request.queryParam(test) }} // output: hello
{{ request.queryParam(lala) }} // output: (empty string)

response.addHeader(name, value)

This call will add a header to the response. This call does not output anything.

{{response.addHeader(ab-test, 4)}}


This call will add a redirect the page.



This call will add a redirect the page.



This call will response to your default 404 page, if there is no default 404 page, a generic 404 page will display with the "message" param as an h1 tag.

{{response.return4040(My Default Message)}}


The sectionlinks() call looks at the current page and searches up to its top-level parent to create a navigation structure as an HTML list. Depth can be specified by as a numeric argument as sectionlinks(2) or you can choose not to display the top level page by passing sectionlinks(off)

{{ sectionlinks() }}
// <ul class="sectionLinks" id="sectionLinks">
<li><a href="/about-us/" title="About Us">About Us</a>
<ul class="sectionLinks">
<li><a href="/about-us/team/" title="">Team</a></li>
<li><a href="/about-us/qualifications/" title="Qualifications">Qualifications</a></li>


Deprecated: this functionality is only available to test in preview, it is not available for production websites because they are statically cached.

This call will access the Navigation Title for an item which is located under an item's Meta information in the Content section.

The sever_var call provides access to some of the most common server variables holding information about headers, paths, and script location. Some available variables are:

{{ this.seo_link_title }}


This call will access the Meta Title for an item which is located under an item's Meta information in the Content section.

{{ this.seo_meta_title }}








{{ server_var.HTTP_USER_AGENT }}


The settings call returns data stored in the Instance Settings in the Config Tab.

<a href="{{ }}">Zesty on Linkedin</a>
// <a href="">Zesty on Linkedin</a>


The instance call returns data specific to the instance, such as the CDN URL and the domain or globally relevant data, such as the current data-time or the current language.

{{ instance.cdn }}


The instance.env call returns live for published content and views, and dev for versioned preview views and content.

{{ instance.env }}

The call returns the current date time and accepts arguments to modify the date based on the PHP data-time. More information available at

{{ jS \of F Y h:i:s A) }}
Sunday 31st of July 2005 08:45:12 PM


The instance.lorem() call auto generates lorem ipsum placeholder content.

{{ instance.lorem(20) }}
// Returns : Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam volutpat quam quis erat tristique pretium.


The instance.searchformatted() call takes a string and a limit as arguments and outputs instance-wide search results based on meta title, meta description, and path.



The slugify() call will concatenate strings by replacing spaces with dashes (-), lowercasing all letters, and stripping out all punctuation.

// if the page title is the string: My New Homepage!
{{ page.title.slugify() }}
// calling slugify on the page title will return: my-new-homepage

sort by / order by

The sort by or order by statement can be used in an each loop to specify a field of the content model used to sort the content entries and which direction. Multiple fields can be specified using a comma separated list. If no sort is specified, the default is creation date. If no direction is specified ascending is the default.

{{ each articles as post where post.featured = 1 sort by desc, post.title limit 10 }}
{{ end-each }}

striptags(start, length)

The striptags call will return a string with HTML tags removed. It also acts as a substring method if a start and length parameter are provided.

// $html = "Hello <h1></h1> users"
{{ $html.striptags() }}
// "Hello users"

substr(start, length)

The substr() call takes the text value it is attached to and returns a substring with the desired length. This call takes both positive and negative numbers. Negative numbers, for example, substr(-5) will return the last five characters in a string. Does not consider whitespace as part of length.

// $description = "This is a longer description that needs shortened!"
{{ $description.substr(0,9) }}...
// "This is a lo..."


The subWords() call returns the first specified number of words from a body of text.

{{ page.content.subWords(3) }}


The trim_zeros() call with take a number like 8.0000000 and just show 8. It will also trim leading zeros as well so a number like 00800.00 will show 800.

// $num = 8.000000000
{{ $num.trim_zeros() }}
// 8


The truepath() call will determine the web URL to access a content entry based on a ZUID. Since one-to-one and internal page fields in store ZUIDs, truepath() is a quick way to access the direct url to that content entry without needing to do an each loop or filter call.

{{ truepath({page.link_to_article}) }}

truepath() can be used in each loops as well, for example {{ truepath(this.zuid) }} or {{ this.zuid.truepath() }} and you can assign it to a Parsley variable as well.

{{each articles as art limit 5}}
{{art.zuid}} <br>
{{$var = {truepath({art.zuid})} }}
VAR: {{$var}}<hr>


The where statement is used to filter content entries in an each loop. Where statements use SQL style conditional statements to determine which entries to pass through the loop. A single each can use multiple conditions using and and or.

{{ each articles as post where post.featured = 1 or post.category = '{page.featured_category}` sort by desc limit 10 }}
{{ end-each }}