How to execute php code in the smarty template _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.