How to output the variable index using the php tag in smarty. phpPHPcode $ smartynewSmarty; $ smarty-& gt; allow_php_tagtrue; $ smarty-& gt; assign (& quot; a & quot;, & quot; aaaaaaaaaaaa & quot ;); $ smarty-& gt; display (how to output variables using the php tag of ind smarty
Index. php
PHP code
$smarty = new Smarty;$smarty->allow_php_tag=true;$smarty->assign("a", "aaaaaaaaaaaaaa");$smarty->display('index.tpl');
Index. tpl
{Php}
Echo $;
{/Php}
Can I use the php tag to output the variable $?
------ Solution --------------------
Assume that the specified smarty delimiter is {}, and then {$}
------ Solution --------------------
Assume that your delimiter is:
In SMARTY, output the PHP variable directly in the following way. However, you must enable allow_php_tag = true in the program;
Echo $;
------ Solution --------------------
Yes. the syntax in the php tag is the same as in the php file.
------ Solution --------------------
{$ }.
------ Solution --------------------
Assume that your separator is: {} directly {$ }.
------ Solution --------------------
The separator is {}, which can be directly {$ }.
------ Solution --------------------
That is, adding an echo is simply an extra step.
------ Solution --------------------
{$}
------ Solution --------------------
{Php}
Echo $ aaaaaaaaaaaa;
{/Php}
------ Solution --------------------
Assign is a variable. just enclose the variables in assign with delimiters on the page.
------ Solution --------------------
In Smarty2, php labels are opened by default, that is, the template is identified by default, and Smarty3 needs to be set. It can also be seen that using php labels in templates is not a recommended practice. LZ can implement the following methods.
PHP code
// Write global $ var in the PHP file like this; // declare the global variable... $ var = 'Hi Smarty '; // value assignment. you do not need to use the assign method of smarty to obtain <{php}> echo $ GLOBALS ['var'] in this way. <{/php}>
------ Solution --------------------
Why use the php label? {variable} is enough. you can use foreach section for loop.
------ Solution --------------------
Direct
{$ A} is enough. if you want to process the data, you can refer to the manual.
------ Solution --------------------
Yes, but you must define the delimiters,
$ Smarty-> left_delimiter = "{php}"; // specify the left delimiter
$ Smarty-> right_delimiter = "/{php}>"; // specify the left delimiter
The echo in the middle is not needed. it is {php} $ a {/php} directly}
------ Solution --------------------
[Php]
Echo "this is the php code ";
[/Php]
You can directly write php code in the template.