Calculating values based on variables
In some cases you need to make calculations based on dynamic variables. In this case you can use Smarty's function math, like in a following example.
Example
In this sample we need to calculate the height of the spacer gif based on the count number of active section. We insert function math into a section loop and assign the result of the equation to the variable called spacer_h to be later used in <img>-tag.
{************ Spacer height ***********}{init_section name="rub1" level="1"}
{foreach from=$rub1 item=obj key=key}
{if $obj->is_selected}
{math equation="((x - 1) * 20) + 12" x=$key assign=spacer_h}
{/if}
{/foreach}
{************// Spacer height ***********}
<img src="{$wwwroot}/px_custom/gfx/px.gif" width="1" height="{$spacer_h}" alt= ""name="Spacer" border="0">
RSS