Thinkphp method _php instance using literal to prevent template tags from being parsed

Source: Internet
Author: User

The example of this article describes the method of thinkphp label direct output to prevent template tags from being parsed. Share to everyone for your reference. The implementation methods are as follows:

You can use the literal tag in thinkphp to prevent template tags from being parsed, for example:

Copy Code code as follows:
<literal>
<if condition= "$name eq 1" > value1
<elseif condition= "$name eq 2"/>value2
<else/> Value3
</if>
</literal>

The IF tag above is included with the literal tag, so the contents of the IF tag are not parsed by the template engine, but are kept as-is output.

If you need to output a situation like {$user} or XML tags in your PHP tags, you can solve the confusion by adding literal tags, such as:

Copy Code code as follows:
<php>echo ' {$Think. Config.custom. ' $key. '} '; </php>

The {$Think in this PHP tag may be mistakenly interpreted as a label by the template engine, and the solution is to add literal, for example:

Copy Code code as follows:
<php><literal>echo ' {$Think. Config.custom. ' $key. '} '; </literal></php>

Literal tags can also be used for the page's JS code outer layer, to ensure that some of the use of JS code and template engine does not create confusion.

All in all, the literal tag can be used where all possible conflicts with the parsing rules of the built-in template engine.

I hope this article will be helpful to everyone's thinkphp framework program design.

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.