Brief introduction of thinkphp template assignment and replacement example
- 2021-08-05 09:18:07
- OfStack
This paper describes the method of thinkphp template assignment and replacement with examples. Share it for your reference. The specific implementation method is as follows:
1. Assignment method in template:
$this->assign('name',' Script House ');// No. 1 1 Kinds of assignment methods
$this->name='jb51';// No. 1 2 Kinds of dynamic assignment methods
$this->display();
2. Template replacement method:
PUBLIC__: Will be replaced with the public directory of the current Web site, typically /thinkphp/Public/; Create Css folder in Public and basic. css file
__ROOT__: Will be replaced with the address of the current Web site (excluding domain name) /thinkphp
__APP__: will be replaced with the current project's URL address (excluding domain name) /thinkphp/index. php;
__GROUP__: Will be replaced with the URL address of the current packet (excluding domain name)/thinkphp/index. php/Index;
__URL__: Replaces the current module's URL address (excluding domain name) /thinkphp/index. php/Index/index;
__ACTION__: Will be replaced with the URL address of the current operation (excluding domain name) /thinkphp/;
__SELF__: Replaces the current page URL
Change template variable rules and modify configuration items
'TMPL_PARSE_STRING'=>array( // Add your own template variable rule
'__CSS__'=>__ROOT__.'/Public/Css', // Specify the file storage directory
'__JS__'=>__ROOT__.'/Public/Js',
),
Invoke the method:
href='__CSS__/basic.css' href='__JS__/basic.css'
I hope this article is helpful to everyone's ThinkPHP framework programming.