Thinkphp uses literal to prevent template tags from being parsed

Source: Internet
Author: User
This article mainly introduces thinkphp's use of literal to prevent template tags from being parsed. It is a very practical technique to achieve direct output of some template tags that do not need to be parsed, for more information, see

This article mainly introduces thinkphp's use of literal to prevent template tags from being parsed. It is a very practical technique to achieve direct output of some template tags that do not need to be parsed, for more information, see

This example describes how thinkphp directly outputs without parsing tags to prevent template tags from being parsed. Share it with you for your reference. The specific implementation method is as follows:

In ThinkPHP, literal labels can be used to prevent template tags from being parsed. For example:

The Code is as follows:


Value1
Value2
Value3

The above if label is included by the literal label, so the content in the if label is not parsed by the template engine, but is output as is.

If your php tag needs to output a tag similar to {$ user} or XML, you can add the literal tag to solve the confusion problem, for example:

The Code is as follows:

Echo '{$ Think. config. CUSTOM.'. $ key .'}';

The {$ Think in this php tag may be incorrectly parsed as a tag by the template engine. The solution is to add literal, for example:

The Code is as follows:

Echo '{$ Think. config. CUSTOM.'. $ key .'}';

Literal labels can also be used in the JS Code outer layer of the page to ensure that some usage in the JS Code is not confused with the template engine.

In short, the literal label can be used to handle all possible conflicts with the parsing rules of the built-in template engine.

I hope this article will help you with ThinkPHP framework programming.

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.