Parsley Index
This index collects all Parsley syntax and methods.
_index
#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.
_length
#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.
_num
#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.
activate_links()
#Converts plain text URLS into anchor tags URL. Useful for content where text comes in with HTML stripped.
api.dribbble
#breadcrumbs
#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.
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.
current_view
#The {{ current_view }}
call is a unique Zesty.io 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.
date(format)
#Uses the php date format to create the date string shown to the user.
dateDiffForHumans()
#This method creates an expression of duration comparing the date and time from a content field to the current date and time.
each
#The Parsley Each statements, also known as loops, allow you to iterate (loop) through each entry of a content model.
else
#The else
statement allows for a a final case if none of the defined conditions in the if
statement have been met.
else-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
.
end-each
#Required to close each
loops.
end-if
#Required to close an if
statement.
escapeForJs()
#The escapeForJs()
call returns text with all the characters that could break a Javascript or JSON string escaped with \
.
filter()
#The .filter()
call can be used to access specific data based on the scope.
find_in_set
#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.
first()
#The first()
call will access the content available in the first entry of any content model.
format_currency()
#The format_currency()
call transforms a float number from a content field to the format $XX.XX.
get_var
#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.
getfeedurl()
#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/
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".
getImageTitle()
#The getImageTitle()
call returns the image title set in the Media Tab.
getMediaURL()
#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 Zesty.io.
getNextURL(number)
#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 10. This can be used with get_var.p
to do pagination with an each loop.
getPreviousURL(number)
#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 10. This can be used with get_var.p
to do pagination with an each loop.
getUrl()
#The getUrl()
call returns the relative path to the entry.
globals
#The globals
call is used to access content stored in the Globals (formerly Content Clippings) set.
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
gravatar()
#The gravatar()
function takes an email address and requests an image from the Gravatar API.
hasChildren()
#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.
html_entity_decode()
#The html_entity_decode
call converts all HTML entities in the provided string to their applicable characters.
htmlentities()
#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.
if
#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.
include
#The include
call is a prompt to reference the code in any View which includes views, snippets, and endpoints.
instance.host_env
#Shows the instance's webengine URL. This only works in preview - not on live.
instance.host_live
#Shows you the instance's first registered domain. This only works in preview - not on live.
instance.host_preview (or instance.host_relative)
#Shows an instance's preview URL. This only works in preview - not on live.
instance.host_protocol
#Shows the instance's protocol based on its settings. This only works on preview - not on live.
last()
#The last()
call will access the content available in the last entry of any content model.
limit
#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.
length()
#The length
of a given string.
math(statement)
#The math()
call executes an equation and returns a number.
navigation(number)
#The navigation()
call will access your Zesty.io Navigation Structure and output it as an HTML list.
The call will mimic the content navigation layout you find in the Zesty.io 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.
number_format(number)
#The number_format()
call returns a number with the specified number of decimals as the argument. Blank will remove any decimals.
obfuscate()
#The obfuscate()
call returns obscure text to web crawlers, like email or phone numbers.
xssProtect()
#The xssProtect()
call encode, decodes, strips html and turns characters into entities.
page
#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.
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
.
post_clean()
#The post_clean()
call replaces \n
\r\n
or \
with a blank string.
post_var
#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.
preg_replace(pattern, replacement)
#The preg_replace()
call is a regular expression replacement. To learn more about Regular expression go to http://www.regular-expressions.info/
random()
#The random()
call is used to reference a random content entry for a content model.
replace(pattern, replacement)
#The replace()
call does a simple replace without any regular expression.
request.path()
#Gets the full path from request excluding query parameters, for example lets use the url /store/12345/my-product/
request.fullpath()
#Gets the full path from request including query parameters, for example lets use the url /store/12345/my-product/?query=newvalue
request.pathPart(num)
#Get the "parts" of a url, for example lets use the url /store/12345/my-product/
request.queryParam(num)
#Get the query parameters from url, for example lets use the url /store/12345/my-product/?test=hello
response.addHeader(name, ...value)
#This call will add a header to the response. This call does not output anything.
response.redirect301(url)
#This call will add a redirect the page.
response.redirect302(url)
#This call will add a redirect the page.
response.return404(message)
#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.
sectionlinks(number)
#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)
seo_meta_description
#Use this call to access an item's meta description.
seo_link_title
#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:
seo_meta_title
#This call will access the Meta Title for an item which is located under an item's Meta information in the Content section.
setting
#The settings
call returns data stored in the Instance Settings in the Config Tab.
toJSON()
#A function outputs a JSON string that can be use in inline JavaScript. The function can be called off this, data calls, or loop variables. Parsley REPL Example https://parsley.zesty.io/turn-any-content-item-to-json/
{{this.toJSON(depth, showMeta)}}
depth
is an integer for hydration depth, max is 5showMeta
true or false:true
gives all meta, routing, and zuid details, and locale details.false
is just content
Example output for {{this.toJSON()}}
call on zesty.io homepage
json()
#Accessing Objects in JSON. Quickly access an object of an object to access its value.
Live example: https://parsley.zesty.io/accessing-a-json-object-within-an-object/
Iterating String Arrays
This refers to support for objects that store arrays of strings without keys.
Live example: https://parsley.zesty.io/iterating-through-a-json-array-of-strings/
json(arr)
#JSON Content Iteration. JSON stored in a content model field can be iterated by using parsley, the same as content items.
Preview a live JSON iteration example here: https://parsley.zesty.io/iterating-over-a-content-stored-json-object-with-an-array/
instance
#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.env
#The instance.env
call returns live
for published content and views, and dev
for versioned preview views and content.
instance.date()
#The instance.date()
call returns the current date time and accepts arguments to modify the date based on the PHP data-time. More information available at http://php.net/manual/en/function.date.php
instance.lorem(number)
#The instance.lorem()
call auto generates lorem ipsum placeholder content.
instance.searchformatted(string,limit)
#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.
slugify()
#The slugify()
call will concatenate strings by replacing spaces with dashes (-), lowercasing all letters, and stripping out all punctuation.
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.
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.
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.
subWords(number_of_words)
#The subWords()
call returns the first specified number of words from a body of text.
trim_zeros()
#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.
truepath(zuid)
#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 Zesty.io 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()
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.
where
#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 Statement Updates
Each statement's code gets reduced with shortcut statements and easier iteration of content relationships.
Content Relationship Iteration
The latest update simplifies the logic and reduces code length by allowing the relationship to be directly referenced in each loop. It also provides a shortened end-each option.
Old Style
New Style
Live example: https://parsley.zesty.io/iterate-through-a-model-relationship-field/
Array Commas
Outputting custom JSON data endpoints with Parsley content syntax requires extra logic if you are outputting an array of objects. This update streamlines that logic. Here is what use to look like to output 10 random articles to JSON.
Old Style
Note the logic does not have a trailing comma. That is what we replace with _arraycomma.
_arraycomma
will always know the last item in your array and will not put a comma after the last value. Otherwise, a comma will be appended after each value.
New Style
Live example: https://parsley.zesty.io/generate-json-output/
Ending Each Iterations and If Logic Statements
A simple change to shorten code for an each statement {{end-each}}
can now be written as {{endeach}}
or {{/each}}
.
If statements can now be terminated with {{/if}}
, {{endif}}
or {{end-if}}
.
Data Access Calls
#Data access calls are streamlined and gain two new functions.
Previous way to access a single item with parsley content syntax:
Old Style
New Style
Live example: https://parsley.zesty.io/directly-access-an-item-of-a-content-model-by-zuid/
Using filter to search
Example of a custom JSON endpoint to get a single item outputted to a fully hydrated JSON object. Make a custom file in code, /data/article.json with code
Then call the endpoint with a ZUID www.domain.com/data/article.json?zuid=7-x1y2z3-x1y2z3
Connect with Content Experts
Book a free 15-minute consultation with a content expert. Discuss your application, pain points and requirements. Understand how Zesty's lower total cost of ownership, features, functionality can elevate your business by creating extraordinary digital experiences.
Trusted By
G2 MOMENTUM LEADER