thinkphp Template Switch Label Usage example _php instance

Source: Internet
Author: User

The switch label in the thinkphp template is used to output different values in the template according to different conditions.

The thinkphp template engine supports switch judgment and can output different results according to different conditions, using the following format:

<switch name= "variable name" >
<case value= "value 1" > Output 1</case>
<case value= "value 2" > Output 2</case >
<default/> Default
</switch>

Examples of usage are as follows:

<switch name= "UID" >
<case value= "1" > Admin </case>
<default/> Visitor
</switch>

Note here:

The Name property can use functions as well as system variables with property values of variable names, no $ symbols, and value values that use variables with a $ symbol , as shown in the previous example.

in the case of variable mode, value values are not supported by multiple conditions , such as the following multiple conditional judgments.

Multi-Conditional judgment:
The Value property of the case can be used to support multiple conditions, using | Symbols for segmentation:

<switch name= "Think.get.type" >
<case value= "gif|png|jpeg" > Image format Files </case>
<default/ > Other format Files
</switch>

This means that if the value of the $_get["type" is GIF, PNG, or JPG, it is judged as an image format.

The Name property can also be a system variable, and you can use a function such as:

<switch name= "Think.get.username|function1" > ...
</switch>

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.