Legacy Documentation
You are using the documentation for version 4.3.8. Go here for the latest version.
Variable Modifiers¶
Most template variables can be modified for common formatting and output needs without requiring any plugins. For instance, making user-submitted content safe for use in a <meta> tag attribute, limiting to a certain number of characters, displaying currency, or as JSON to create structured data for SEO. These modifiers apply to:
- All Channel Fields
- URL Segment Variables
- Embed Variables
- Layout Variables
- Template Route Variables
- Standard Global Variables
- User-defined Template Variables
- All add-ons that use native APIs for parsing variables in templates
Available variable modifiers:
Note
Some add-ons and components may have modifiers not listed here. For instance the File Fieldtype has its own file information-related modifiers. The modifiers listed here are just those universally available.
:attr_safe¶
Makes content safe for use in an HTML attribute. It strips HTML tags, encodes special HTML characters, and can optionally limit the length of the content.
<meta name="description" content="{seo_descrip:attr_safe limit='150'}">
Parameters: |
|
---|
:censor¶
Censor naughty words, using the site’s Word Censorship settings.
{variable:censor}
{!-- Some ####### content with naughty words censored --}
:currency¶
Format a number as currency.
{cost:currency}
{!-- $142.73 --}
{cost:currency currency='EUR' locale='de_DE'}
{!-- 142,73 € --}
{cost:currency decimals='0'}
{!-- $399,000 --}
Parameters: |
|
---|
Note
For non-US locale support, the PHP intl
extension must be installed. Thankfully the PHP intl extension is available by default, so your environment would have had to intentionally disabled it (why??) for it to be unavailable.
:decrypt¶
Decrypt the content.
{secret:decrypt}
{!-- No more secrets --}
Parameters: |
|
---|
:encrypt¶
Encrypt the content.
{secret:encrypt}
{!-- H8JwSqsqVYUCvYBUmKqaXjO4VzLsyj791dtim3EfJT8= --}
Parameters: |
|
---|
:form_prep¶
Make the content safe to use as the value of a form field.
<input name="myField" type="text" value="{excerpt:form_prep}">
{!-- <input name="myField" type="text" value="A <em>brief</em> discussion about "Wonko the Sane""> --}
:json¶
Encode the content for JSON output.
"headline": {title:json},
// "headline": "Greatest Crash in Wall Street\u2019s History",
:limit¶
Limits the content to the specified number of characters. May be fewer than the exact limit, as this retains whole words.
{excerpt:limit characters='20'}
{!-- A discussion… --}
Parameters: |
|
---|
:ordinal¶
Formats a number with its ordinal suffix.
{rank:ordinal}
{!-- 42nd --}
{rank:ordinal locale='es_ES'}
{!-- 42.º --}
Parameters: |
|
---|
Note
For non-US locale support, the PHP intl
extension must be installed. Thankfully the PHP intl extension is available by default, so your environment would have had to intentionally disabled it (why??) for it to be unavailable.
:raw_content¶
Output the raw, unparsed content of the variable, for example as stored in the database with no typography variable interpolation. Useful for creating content export templates.
{checkbox:raw_content}
{!-- IL|OR|HI --}
:replace¶
Replace text within the content.
{content:replace find='the cloud' replace='my butt'}
{!-- ...enabling you to easily store mass volumes of data in my butt. --}
{full_name:replace find='/(.*?),\s*(.*)/' replace='$2 $1' regex='yes'}
{!-- John Doe (presuming {full_name} is "Doe, John") --}
Parameters: |
|
---|
:rot13¶
Perform a ROT13 substitution cypher to the content.
<span class="spoiler" data-secret="{spoiler:attr_safe}">{content:rot13}</span>
{!-- <span class="spoiler" data-secret="He was dead the whole time!">Ur jnf qrnq gur jubyr gvzr!</span> --}
:spellout¶
{rank:spellout}
{!-- forty-two --}
{rank:spellout capitalize='ucfirst'}
{!-- Forty-two --}
{rank:spellout locale='de_DE'}
{!-- zweiundvierzig --}
Parameters: |
|
---|
:url¶
Normalize a URL to use in markup. Primarily to make sure it contains a valid protocol. For instance if {website}
was www.example.com
:
{website:url}
{!-- http://www.example.com/ --}
Note that it is best to use a URL field, so this is more useful for values coming from plugins or outside sources.
:url_decode¶
URL decode the contents.
<h1>Location: {segment_2:url_decode}</h1>
{!-- <h1>Location: New Zealand</h1> --}
Parameters: |
|
---|
:url_encode¶
URL encode the contents.
<a href="{path='view/{location:url_encode}'}">{location}</a>
{!-- <a href="https://example.com/view/New%20Zealand}">New Zealand</a> --}
Parameters: |
|
---|
:url_slug¶
Create a URL slug from the content.
{excerpt:url_slug}
{!-- a-phrase-with-words-from-the-stopwords-list --}
{excerpt:url_slug remove_stopwords='yes'}
{!-- phrase-words-stopwords-list --}
Parameters: |
|
---|