'Can we define variables in `.tpl` files?
In general, if we have a Smarty project we assign variables in .php
file, and use the variables in its corresponding .tpl` file.
such as:
$smarty->assign('foo', 'Foo'); // in .php file
{$foo} // in .tpl file
can we define the variables in .tpl
? and if can, is this recommend?
and why?
Solution 1:[1]
Yes, you can:
{assign var="foo" value="Foo"}
{assign "foo" "Foo"} {* short-hand *}
The value of $foo is Foo.
Solution 2:[2]
Use in smaartly by calling to $ss->assign('i', $i);
and in your .tpl
file you can access it with the {$i}
notation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Adam Genshaft |