Php-smarty-4 (21)

Source: Internet
Author: User
Smarty Function---plug-in

1) built-in function sysplugins does not allow modification

2) Custom Function plugins can be modified

1. Capture captures a piece of content, but does not output

Grammar:

{Capture name= ' var '}

Content

{/capture}

Name: Save the content to the specified variable

{$smarty. Capture.var}

In the template, a large amount of content that needs to be output over and over again can be considered using capture captures.

2. config_load Load configuration file

{config_load file= "file" section= "section"}

File: Profile Name

Section: Which configuration sections to refer to optional parameters

Reference syntax:

{#var #}

{$smarty. Config.var}

3. Foreach,foreachelse for traversing arrays

Grammar:

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

{Foreachelse} when the array to be traversed does not have any elements, execute the statement after Foreachelse

{/foreach}

From: Array to traverse

Item: The key value to traverse to

Key: The name of the keys that are traversed

Name: Name the foreach statement

foreach Built-in variables

$smarty. Foreach.name.index: Index starting from 0

$smarty. Foreach.name.iteration: Index starting from 1

$smarty. Foreach.name.first: This value is true when the loop is executed for the first time

$smarty. Foreach.name.last: This value is true when the loop is last executed

$smarty. Foreach.name.total: Total number of loops

4. Include referencing another template file

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

File: Template files to be introduced

Assign: Saves the result, but does not output this time

[var ...] : Optional parameters, parameter for template file

5. include_php contains a PHP file

{include_php file= "file" assign= "var" once= "True|false"}

File: PHP files to be introduced

Assign: Save output, but not output at this time

Once: Contains only one time true: false: No

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

6, insert in the template, execute a PHP function

Grammar:

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

Name: called PHP function name

[var ...] : Specify parameter optional parameters when calling function

Insert and include_php are the same. Are all functions in the 2.6, and in 3.0, this function is placed 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, Ldelim, Rdelim the escape character of {} in template

{Ldelim}

{Rdelim}

9, literal literal mark in the middle of the content will not be resolved by smarty

{literal}

......

{/literal}

10. PHP can write PHP code in a pair of PHP tags

{PHP}

......

{/php}

The above describes the Php-smarty-4 (21), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.