Helper Plugin
The helper plugin handles useful little things like formatting, language strings, and counting.
helper:lang
{{ helper:lang }}
Displays a language string from the current language.
Attributes
| Name | Default | Required | Description |
|---|---|---|---|
| line | None | Yes | The array key of the language string that you wish to display. |
Example
{{ helper:lang line="global:control-panel" }}
Returns (if the current language is English):
"Control Panel"
helper:config
{{ helper:config }}
Displays a configuration item.
Attributes
| Name | Default | Required | Description |
|---|---|---|---|
| item | None | Yes | The config item to display. |
Example
{{ helper:config item="default_language" }}
Returns (if the default language is English):
"en"
helper:date
{{ helper:date }}
Displays a date in the format defined in Control Panel → Settings or in the format specified.
Attributes
| Name | Default | Required | Description |
|---|---|---|---|
| format | Set in CP → Settings | No | The date using php date formatting. |
| timestamp | Current time | No | Pass an epoch or MySQL timestamp to format a date in the past or future. |
Example
{{ helper:date format="m/d/Y" }}
Returns:
The current date in "04/20/2012" format.
Example
{{ blog:posts }}
Title: {{ title }}
Posted On: {{ helper:date format="d/m/Y" timestamp=created_on }}
{{ /blog:posts }}
Returns:
Title: Test Blog Post
Posted On: 31/01/2012
helper:gravatar
{{ helper:gravatar }}
Displays an avatar linked to the provided email address at gravatar.com
Attributes
| Name | Default | Required | Description |
|---|---|---|---|
| None | Yes | The email linked to the avatar. | |
| size | 50 | No | The width of the image, in pixels. |
| rating | g | No | The content rating of the avatar. |
| url-only | false | No | Fetch the URL only or a complete image tag. |
Example
{{ helper:gravatar email="test@pyrocms.com" }}
helper:count
{{ helper:count }}
Count the number of items being output in a tag loop
Attributes
| Name | Default | Required | Description |
|---|---|---|---|
| identifier | default | No | An identifier to make each counter unique if using multiple counters on the same site. |
| start | 1 | No | The number to start counting at. |
| mode | add | No | Whether to add or subtract from the start number. |
| return | true | No | Output the count result on each loop or just increment the counter silently. |
Example
{{ blog:posts }}
{{ helper:count mode="subtract" start="10" }} -- {{ title }}
{{ /blog:posts }}
Outputs:
10 -- This is an example title
9 -- This is another title
You can add a second counter to a page by setting a unique identifier:
{{ files:listing folder="foo" }}
{{ helper:count identifier="files" return="false" }}
{{ name }} -- {{ slug }}
{{ /files:listing }}
You have {{ helper:show_count identifier="files" }} files.
helper:show_count
A helper tag that works together with the above tag as shown in its last example. It can be placed anywhere on the page after the counter and it will only display the value without incrementing the count.
helper:[function]
{{ helper:[function] }}
Executes a whitelisted PHP function on your data. Attributes are passed to the function as arguments.
Attributes
| Name | Default | Required | Description |
|---|---|---|---|
| [wildcard] | None | Yes | You must pass the arguments that the function requires as attributes. The attribute name is discarded. |
Example
In this example we will assume that the variable contains this string:
<div class="test">My Test is %s</div>
// note that you could name the attribute anything you want here. I used "value" as that is explanatory
{{ helper:strip_tags value=html }}
Returns:
My Test is %s
Now we'll use sprintf and pass both the string and the value as sprintf requires at least two arguments.
{{ helper:sprintf string=html status="Complete" }}
Returns:
My Test is Complete
Allowed Functions
The functions that can be used are defined in system/cms/config/parser.php
This is the current list:
- character_limiter
- count
- count_chars
- empty
- explode
- format_date
- html_entity_decode
- htmlentities
- htmlspecialchars
- htmlspecialchars_decode
- implode
- is_array
- is_int
- is_integer
- is_string
- isset
- ltrim
- md5
- money_format
- number_format
- preg_match
- preg_replace
- rtrim
- safe_mailto
- sprintf
- str_replace
- str_word_count
- strip_tags
- strpos
- strtolower
- strtoupper
- substr
- trim
- ucfirst
- ucwords
- word_censor
- word_limiter
- wordwrap
