Search code examples
mathsmartyarithmetic-expressionssmarty2

What's wrong with the smarty arithmetic I did?


Following is the smarty arithmetic code I tried but it's not working:

{if $cur_page == 1} {assign var='i' value=1} {else} {assign var='i' value=$cur_page * 15  + 1} {/if}

Can someone please correct my code? If you want any other information regarding the issue please do let me know.


Solution

  • It simply won't work in Smarty2. In Smarty3 this code will work without a problem.

    In Smarty2 you should use math() function to achieve the same so the working code in Smarty2 for that would be:

    {if $cur_page == 1}
        {assign var='i' value=1}
    {else}
        {math equation="x* 15 + 1" x=$cur_page assign='i'}
    {/if}