Documentation

Syntax

Variables

Those are the simplest thing to handle in PyroCMS, you just need to know the variable name and you can output it like that: {$name}. So let's say you have a variable called date, you would output it using {$date}.

To handle arrays, if you have for example a variable called article that contains three items, title, author and content, you can access the sub-items by separating the array name and the sub-item by a dot (.) so that it looks like this for example :

<p>The date is {$date}</p> 
<div class="article">
<h1 class="title">{$article.title}</h1>
<p class="content">{$article.content}</p>
<p class="title">Posted by : {$article.author}</p>
</div>

Functions

The function syntax is quite flexible, functions can either be called just like in php, using {upper("hello")} to call the function upper with the parameter hello. This would print HELLO, as the upper function's purpose is to make strings uppercased. In this case the multiple parameters are split using a comma, i.e. {function("a", "b")} will call function with two parameters, a and b.

Here are some {upper("uppercased words")}
prints :
Here are some UPPERCASED WORDS

The other way is to call a function using named parameters, the same example as above would then become {upper value="hello"}, in this example we explicitly tell it to use hello as the value.

Here are some {upper value="uppercased words"}
prints :
Here are some UPPERCASED WORDS

Both ways have pros and cons. The first one is shorter and allows you to forget about parameter names, but the second is more flexible when it comes to complex functions with a lot of parameters, because it not only allows you to forget about their order, but you can also skip parameters and provide only those you really need.

Modifiers

Modifiers are simply functions that can be applied on variables or strings to modify them, this syntax is not mandatory, modifiers like upper can be called using the function syntax without any problem, but the alternative exists if you prefer it. To make hello uppercased using the upper function as a modifier, you must do {"hello"|upper}.

Abcd reversed is {"Abcd"|reverse}
prints:
Abcd reversed is dcbA

Modifiers parameters are split with ":", and multiple modifiers can be applied on the same variable/string as such :

{"test"|spacify:"-"|reverse|upper} equals {upper(reverse(spacify("test", "-")))}
prints:
T-S-E-T equals T-S-E-T

This example shows that multiple functions are applied from "inside" the parenthesis (right) to the "outside" (left), while multiple modifiers are applied from left to right.

As PyroCMS runs on Dwoo, this page was taken from the Dwoo Wiki.

« Back to "Designers Guide"


Hosted by CloudIgniter
Click here to lend your support to: pyrocms and make a donation at www.pledgie.com !