Patterns

Top  Previous  Next

Patterns are special blocks of code used for repeating data. For example, if a page contains a list of some objects of the same type, a pattern is used to create HTML for every object. Different types of objects would use different patterns.You can define a pattern in any part of the template. Keep in mind that a pattern must not be defined in an include! The syntax of a pattern is the following:

 

 

<<object>>

Some data and variables here.

<</object>>

 

For example, a page contains a list of toys and each toy has 3 variables associated with it: $name, $color, $price. The template file may look the following way:

 

 

<h1>List of toys:</h1>

<UL>$toys</UL>

 

<<toy>>

  <LI>$name ($color) - $ $price</LI>

<</toy>>

 

 

During the page process the data coming from the API is used to populate the variables for each toy. At this time the <<toy>> pattern is used (with the variables populated) and the contents of it are added to the $toys variable. In the end the $toys variable is shown in the browser (the pattern code is destroyed before sending HTML to the browser, as it was used already to populate the $toys variable). The output can look like the this:

 

 

<h1>List of toys:</h1>

<UL>

<LI>Spiderman (black) - $ 50</LI>

<LI>Teddy Bear (brown) - $ 30</LI>

</UL>

 

 

To learn about the specific patterns and variables they are used to populate please refer to the API documentation and examples.