Posts

Showing posts with the label smarty

How do you increment an assigned variable in smarty without displaying it

How do you increment an assigned variable in smarty without displaying it So I have an assigned variable in smarty: {assign var=number value=0} Now I can increment it using {$number++} or {++$number} Which is exactly what I need, only problem is, it displays the value of $number on the page. Is there a way I can increment the value but not display it? This is not used inside of a loop otherwise I would use something like iteration or index. 4 Answers 4 You could do this: {assign var=val value=1} {assign var=val value=$val+1} {$val} // displays 2 The above will be compiled to: $this->assign('val', 1); $this->assign('val', $this->_tpl_vars['val']+1); echo $this->_tpl_vars['val']; or {assign var=var value=1} {capture assign=var}{$var+1}{/capture} {$var} // displays 2 Which in turn will be compiled as: $this->assign('var', 1); ob_start(); echo $this...