tags:

views:

34

answers:

3

I tried this way,but seems not working:

{if $i == 1}
    $value = $recommend[3];
{/if}

Does smarty support assignment operation?

A: 

There is assign() method for that. Check it out here:

http://www.smarty.net/manual/en/api.assign.php

Sarfraz
I think he means how to do it in a template, rather than the PHP biz logic.
webbiedave
A: 

Another option besides assign() ( which is probably better from separation of code and presentation point of view) is http://www.smarty.net/manual/en/language.function.php.php

Mark Steudel
+1  A: 

To assign variables within a template, do:

{if $i == 1}
    {assign var='value' value=$recommend[3]}
{/if}
webbiedave
What about `{$value = $recommend[3]}` ?
yoyo
@yoyo: You should call the assign function. From the docs: `{assign} is used for assigning template variables during the execution of a template.` http://www.smarty.net/manual/en/language.custom.functions.php#language.function.assign
webbiedave
@yoyo what about moving this assignment into business logic part? There is no such restrictions there.
Col. Shrapnel