ez.no / exponential / documentation / customization / custom design / examples / template language
The Exponential template language is built around a special syntax to extinguish it from HTML and is built up around variables, functions and operators.
Template functions take named parameters and can work on sub children elements that can be functions or text. Operators (see previous section) work like Unix pipes where the data is input in one end, processed and output to either a new operator or to the output. Operators also take sequenced parameters to modify their behavior. Mixing operators and variable types both as parameter and as input works.
The most common program flow is done through the template functions section and switch. In addition the let construction allows you to create variables.
Example: Creating a variable and executing an if construction
{let var='Hello world'} {section show=$var|is_string()} {$var} {/section} {/let}
This little example creates a variable named var containing the text "Hello world". It then checks if the variable var is actually a string type using the template operator is_string. Calls to template operators are done reading from left to right. In this case the contents of $var are fed into the operator is_string. We could have added another pipe after the is_string() call. E.g to invert the result we could use "$var|is_string()|not".
The section function will check if the show attrite evaluates to true. If not the contents of the section will not be displayed. In this case the variable var contains a string ("Hello world") and the contents of the section will be executed. In this case simply printing the string.
We can learn several things from this little example:
Of course you can have comments in your code:
{* this is a comment *}
Of course you want to display data from your Exponential database. This is done using the fetch operator.
{let test=fetch(content,list,hash(parent_node_id,220))} {section name=MyList loop=$test} {node_view_gui view=line content_node=$MyList:item} {/section} {/let}
This example introduces a lot of new things.
First we create the variable test and fill it with data using the fetch operator. In this case we fetch data from the content module, namely a list of objects who have node 220 as their parent.
Then we continue by looping over the contents of this list using a section. Notice that we use the name attribute to open a new namespace for the section. For each iteration the element we are looping through is set in the special variable item. Since we are inside the MyList namespace we can address this variable using $MyList:item.
Finally the contents of each item are displayed using the node_view_gui function. This function will open a new template displaying the contents of each item. You may ask: "why is it done like this?". The answer is: You don't know the class type of each item that you have fetched and you may want to display them all in a special manner. Now you could have done this using a lot of if/else sentences. However this does not promote reusability. Therefore the display of each type has been put in a separate template. The node_view_gui simply picks the correct one.
Have a look at the page data fetching for more information about fetch.
{section name=Folder loop=$folder_list} <tr> <td class="menuitem"> <a class="small" href={concat("/content/view/full/",$Folder:item.node_id,"/")|ezurl}> {$Folder:item.name}</a> </td> </tr> {/section}
a) Current design: operator ezdesign
...prepends the current sitedesign to the url, if the file does not exist in that design the standard sitedesign is used instead.
{"stylesheets/style.css"|ezdesign} => "/design/mydesign/stylesheets/style.css"
b) Current image directory: operator ezimage
...prepends the current sitedesign to the url with the image subdirectory, if the file does not exist in that design the standard sitedesign is used instead. ...Parameter (single): single quotes; no parameter: double quotes.
{"search.png"|ezimage(single)} => '/design/mydesign/images/search.png'
c) Correct URL: operator ezurl
...prepends the string to a given URI that gives a valid URL in the current setup.
{"/content/view/full/132"|ezurl} => "http://yourdomain.com/user/content/view/full/132" => "http://yourdomain.com/index.php/user/content/view/full/132" (nVH)
The variable $site.uri.uri gives the current URI.
A good reference to all the template operators is here..
And a nice list of all the template functions can be found here
After that I strongly suggest you install the demo data, browse through the demo site, identify a few displays that you want to learn how to do and then find the template in the directory structure that does just that.
Log in or create a user account to comment.
Comments
Document links
Amina Bacar
Saturday 27 December 2003 9:57:22 am
I always get the message "Module not found" and it is not this particular article, it happens in several articles.
Amina.