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 about how thinkphp directly outputs without parsing tags, see the example in this article 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.