Php-Smarty-7 (24)

Source: Internet
Author: User
: This article mainly introduces the php-Smarty-7 (24), for PHP tutorials interested in students can refer to it. III. Methods

L assign: assign variables to the template

L assignByRef: assign variables to the template (pass by reference)

L append: append the template variable to an array.

L appendByRef: append Template variables to an array (passed by reference)

L clearAllAssign

Clear all assigned variables

L sort ache

Clear Cache

L configLoad load the configuration file

In smarty, there are two ways to load the configuration file:

1) in the template {config_load file = '.... '}

2) in the program $ smarty-> configLoad ($ file [, $ section])

L clearConfig

Clear all configuration file variables

L display

Read, replace, and output

L fetch

Read, replace, and return

L templateExists: determines whether the template exists

If you try to load a template that does not exist, an error will be reported. you should judge before it is displayed.

Differences between assign and assignByRef:

Difference between Display and fetch:

IV. filter

A filter is used to filter data.

1. filter types:

1) prefilter Prefilters

2) Postfilters

3) Output filter Output Filters

Based on the trigger time, the above three filters are divided

2. workflow

Tpl source file => Prefilter => compile tpl file => Postfilter => save to disk => run the compiled PHP file => Output Filters (=> if there is a smarty cache, output Filters content will be cached) => result Output.

3. Register a filter

In Smarty, the filter must be registered before use

In 2.6, register the filter

L Prefilters

$ Smarty-> register_prefilter ("func ");

L Postfilters

$ Smarty-> register_postfilter ("func ");

L Output Filters

$ Smarty-> register_outputfilter ("func ");

Register different filters to call different methods.

3.0, register the filter

$ Smarty-> registerFilter ($ type, $ callback );

$ Type: filter type

Value range:

Pre: Pre-filter

Post: Post filter

Output: Output filter

$ Callback: filter function

4. Code:

The pre-filter and post-filter will be executed during the first compilation, or the template will be executed again after the template changes.

The output filter is executed every time.

The above introduces the php-Smarty-7 (24), including the content of the aspect, hope to be interested in PHP Tutorial friends help.

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.