Php-Smarty-4 (21), phpsmarty-421_PHP tutorial

Source: Internet
Author: User
Php-Smarty-4 (21), phpsmarty-421. Php-Smarty-4 (21), phpsmarty-421Smarty functions --- ins 1) built-in functions sysplugins do not allow modifications 2) custom functions plugins can modify 1. capture captures a piece of content, php-Smarty-4 (21), phpsmarty-421

Smarty function --- plug-in

1) the built-in function sysplugins cannot be modified.

2) the user-defined function plugins can be modified.

1. capture captures a piece of content but does not output

Syntax:

{Capture name = 'var '}

Content

{/Capture}

Name: save the content to the specified variable.

{$ Smarty. capture. var}

You can use capture to capture a large amount of content that needs to be output repeatedly in the template.

2. config_load load the configuration file

{Config_load file = "file" section = "section "}

File: configuration file name

Section: Which configuration section can be referenced? optional parameters

Reference syntax:

{# Var #}

{$ Smarty. config. var}

3. foreach and foreachelse are used to traverse arrays.

Syntax:

{Foreach from = array key = key name = name item = content}

{Foreachelse} when the array to be traversed does not have any elements, run the statement following foreachelse.

{/Foreach}

From: array to be traversed

Item: The Retrieved key value.

Key: The name of the retrieved Key.

Name: Name of the foreach statement

Foreach built-in variables

$ Smarty. foreach. name. index: the index starts from 0.

$ Smarty. foreach. name. iteration: the index starts from 1.

$ Smarty. foreach. name. first: This value is true when the first loop is executed.

$ Smarty. foreach. name. last: This value is true when the last loop is executed.

$ Smarty. foreach. name. total: total number of cycles

4. include references to another template file

{Include file = "file" assign = "var" [var...]}

File: template File to be introduced

Assign: save the result, but do not output this time

[Var…] : Optional parameter, passing parameters for the template file

5. include_php contains a php file.

{Include_php file = "file" assign = "var" once = "true | false "}

File: The php File to be introduced.

Assign: saves the output result, but does not output this time.

Once: whether to include only Once. true: false: no

This function is available in smarty2.6, but this function is removed in 3.0. if you want to use this function, you can reference the class file SmartyBC. class. php.

6. insert a php function in the template.

Syntax:

{Insert name = "func" [var...]}

Name: Name of the called php function

[Var...]: specifies an optional parameter when calling a function.

Insert and include_php are the same. All are functions in 2.6. in 3.0, put this function in the SmartyBC. class. php file.

Note: the name of the php function referenced by inser must be prefixed with insert _.

7. if elseif else

{If}

{Elseif}

{Else}

{/If}

8. escape characters of {} in ldelim and rdelim templates

{Ldelim}

{Rdelim}

9. the content in the literal mark will not be parsed by smarty.

{Literal}

......

{/Literal}

10. php code can be written in a pair of php tags.

{Php}

......

{/Php}

Http://www.bkjia.com/PHPjc/993264.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/993264.htmlTechArticlephp-Smarty-4 (21), phpsmarty-421 Smarty function --- plug-in 1) built-in function sysplugins cannot be modified 2) custom function plugins can be modified 1, capture a piece of content ,...

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.