Smarty-2014-02-28

Source: Internet
Author: User
Tags smarty template

When using smarty to call the CSS & Javascript file using relative paths in the TPL file, the reference object of this relative path is actually written by calling the PHP file of the TPL file.

If I call template/index. TPL in the index. php file, the relative path of CSS & Javascript file used in index. TPL is relative to index. php.

The path of these files.

Display usage:

// From PHP script, for Linux

$ Smarty-> display ("file:/export/templates/index. TPL ");

$ Smarty-> display ("file:/path/to/My/templates/menu. TPL ");

 

// From PHP script, for Windows

$ Smarty-> display ("file: C:/export/templates/index. TPL ");

$ Smarty-> display ("file: F:/path/to/My/templates/menu. TPL ");

 

Include usage:

{Include file = "template storage path "}

// From within smarty template, for Windows & for Linux

{Include file = "file: D:/usr/local/share/templates/navigation. TPL "}

{Include file = "file =" file:/usr/local/share/templates/navigation. TPL "}

 

Foreach usage:

{Foreach [name = "The Name Of The foreach loop for accessing foreach properties"] From = "the name of the array you are looping through" item = "the name of the variable that is current element "}

......

{/Foreach}

You can also use $ smarty. foreach. foreachname. varname to access the attributes of foreach. foreachname indicates the name attribute value specified in foreach;

Varname:

Iteration (iteration is used to display the current loop iteration, iteration always starts with 1 and incremented by one each iteration );

First (first is set to true if the current foreach iteration is the first one );

Last (last is set to true if the current foreach iteration is the last one );

Show (show is used as a parameter to foreach. show is a Boolean value, true or false. if false, the foreach will not be displayed. if there is a foreachelse present, that will be alternately displayed .);

Total (total is used to display the number of iterations that this foreach will loop. This can be used inside or after the foreach .)

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.