Smarty 1 for php development

Source: Internet
Author: User
The smarty configuration of php development will not be mentioned here. Here we will talk about two of these functions.
(1) assign method
Assign is used to assign values to the template variables when the template is executed. the syntax format is as follows:
{Assign var = "value ="}
The var parameter is the name of the variable to be assigned, and the value of the parameter is the value assigned to the variable.

(2) display method
Display is used to display templates. a valid template resource type and path need to be created.
The syntax format is as follows:
Void display (string template [, string cache_id [, string compile_id])
The cache_id parameter is an optional parameter used to specify the cache number. The compile_id parameter is an optional parameter used to specify a compilation number. The compile number can be used to compile a template into different versions. For example, templates can be compiled for different languages. Another function of the compilation number is to create a compilation number for each templatedir Template directory if multiple templatedir template directories exist but only one compile_dir directory is archived after compilation, to avoid overwriting the same template file after compilation. You can set the compilation number at one time by setting the compile_id compilation number attribute.

The sample code is as follows:

 Template_dir = BASE_PATH.SMARTY_PATH. 'Templates/'; $ smarty-> compile_dir = BASE_PATH.SMARTY_PATH. 'Templates _ c/'; $ smarty-> config_dir = BASE_PATH.SMARTY_PATH. 'configs/'; $ smarty-> cache_dir = BASE_PATH.SMARTY_PATH. 'cache/'; // use the Smarty value assignment method to send a pair of names/methods to $ smarty-> assign ('title', 'Jack's first Smarty Project') in the template '); $ smarty-> assign ('content', 'Hello welcome to study Smarty '); // Display template $ smarty-> display('index.html');?>

The running result is as follows:

Related Article

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.