search
HomePHP FrameworkThinkPHPHow to modify template tag delimiter in thinkphp

How to modify template tag delimiter in thinkphp

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(&#39;test&#39;);

}else{

Alert(&#39;&#39;);

}

</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(

&#39;TMPL_L_DELIM&#39;=>&#39;<{&#39;,

&#39;TMPL_R_DELIM&#39;=>&#39;}>&#39;,

);

?>

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:

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!

Statement
This article is reproduced at:51php. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools