How to execute php code in the smarty template. The main purpose of the Smarty template is to separate the logical layer and the presentation layer. Therefore, the template should not contain the logical part, and the logical layer should not contain HTML. To insert a logical program into a template, the Smarty template mainly aims to separate the logical layer and the presentation layer. Therefore, the template should not contain the logical part, and the logical layer should not contain HTML. This "very" approach to inserting logical programs in the template is not recommended in your case.
If you really need to use the script program in the template, smarty also provides the {php} tag, allowing programmer to mix php code in the presentation layer (again: this is not conducive to the separation of the logical layer and the presentation layer, and violates the separation of the program and structure ). Let's take a look at how to insert php code in the template:
PhpCode. tpl:
1. {php}
2. echo "There is php code in the template of smarty ";
3. for ($ I = 1; $ I <= 3; $ I ++ ){
4. echo "but it's better to avoid php code in your case! ";
5 .}
6. {/php}
PhpCode. php
1. 2. include ("libs/smarty. class. php ");
3. $ smarty = new smarty ();
4. $ smarty-> display ("phpCode. tpl ")
5.?>
:
From desert snail 80
Bytes. Insert the logic program in the template...