Reputation: 17516
I want to add a constant value to a variable in smarty. just like:
{assign var='c' value='0'}
$c=$c+1
Upvotes: 7
Views: 27046
Reputation: 18766
Try this:
{assign var='c' value=0}
{assign var='c' value=$c+1}
The short form should work too, but you say it doesn't.
{$c=0}
{$c=$c+1}
But this doesn't work because you're using Smarty 2, right? Because in Smarty 3 it should work.
Upvotes: 19
Reputation: 51950
You can use expressions with the {assign}
template function.
{assign var=c value=$c+1}
Or in its short form,
{$c=$c+1}
Upvotes: 3
Reputation: 20859
Try:
{assign var="c" value="`$something+$constant`"}
But usually the sense of template frameworks is to follow the mvc pattern. So all the logic is done in a controller. Or in the case of you some sort of php script. The view should not hold much logic(less logic better view code). So any sort of calculations should not be in a view. In mvc you will have however some sort of logic like iterations or link generation(through e.g. smarty plugins).
Upvotes: 4