Expressions - are special entities of macro template that have two main functions:
You can also apply one or several filters (other name is «formatters») to modify expression value or apply some special formatting.
So, expressions has the following syntax: {$Expression[|filter1|filterN]}
Expressions like {$item.title} - we call «path-based expressions». Path to variable may has several elements separated with dots. MACRO splits such expressions into components and generates approximately the following code for each component:
if((is_array($sub_var1) || $sub_var1 instanceof ArrayAccess) && isset($sub_var1[$stepN])) $sub_var2 = $sub_var1[$step2]; else $sub_var2 = "";
$sub_varN - is a temporary variable, and $stepN - one of the elements of variable path. This means what all steps before final element should be arrays or support ArrayAccess interface. If expression can't proceed any deeper into path, an empty string will be used as expression value.
Expressions are also supports method calls or accessing object attributes directly. Just use arrow symbol as the follows:
{$#some_object->someMethod()} {$#some_object->attr1}
You can pass any arguments into method:
{$#some_object->someMethod("aaa", $#foo)}
You can continue path-based expression after method call, for example:
{$#book->getAuthor().full_name}
The last example will be compiled into something like this:
$temp_var = $this->book->getAuthor(); if((is_array($temp_var) || $temp_var instanceof ArrayAccess) && isset($temp_var['full_name'])) $sub_var = temp_var['full_name']; else $sub_var = "";
You should know what macro applies html filter (an alias for htmlspecialchars()) for all output expressions without other filters. If you don't need html filter to be applied to some particular expression you can use raw filter that does nothing but cancels html-filter applying.
Her is a list of different situations:
Обсуждение