Everyone knows that in thinkphp, we assign variables to the template in the controller, and then obtain the variables through tags in the template. Suppose there is a variable is $name, then we should pass it in the template.
{$name} is used to get the variable value. The problem arises here. Suppose there are other JS and CSS in our template. For example, I have a piece of JS code in the template as follows. :
<script type="text/javascript"> Var str=6; If(str>=6){ Alert('test'); }else{ Alert(''); } </script>
If the template contains the above JS code, thinkphp will report an error when parsing the template, because the {} delimiter also appears in this JS, thinkphp will think that { } inside is also a template tag, and then it is parsed, but it is actually just a piece of JS code, so an error is reported.
How should we deal with this situation? Let's take a look at how to modify the delimiter in thinkphp:
In thinkphp, many operations to modify the system default things are implemented through the configuration file. Modifying the label delimiter is also done through the configuration file. It is specified in it. Let’s take a look at how to do it specifically. Add the following code in config.php:
<?php return array( 'TMPL_L_DELIM'=>'<{', 'TMPL_R_DELIM'=>'}>', ); ?>
We can also see from the above code that the label delimiter has been changed to <{ }>, that is to say, if we assign a variable $this->assign('name',$name) in the controller now, we should write like this in the template: <{$name}> ;, so that it will not conflict with JS or CSS.
Recommended tutorial: "TP5"
The above is the detailed content of How to modify template tag delimiter in thinkphp. For more information, please follow other related articles on the PHP Chinese website!