Home  >  Article  >  Backend Development  >  Summary of how to use ThinkPHP's built-in template engine_PHP tutorial

Summary of how to use ThinkPHP's built-in template engine_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:31:13980browse

ThinkPHP’s built-in template engine is an independently innovative XML compilation template engine. The following uses a case to share the usage of some commonly used template tags in ThinkPHP’s built-in template engine, including variable output, looping, judgment, comparison, etc. , these are relatively basic usages and cannot include all tags and features of ThinkPHP's built-in template engine.

(1) The following is the source code of the controller IndexAction class

<?php
class IndexAction extends Action{
    public function index() {
        $_SESSION['name']    =    'ThnkPHP Session';
        $vo    =    array('id'=>1,'name'=>'ThinkPHP','email'=>'liu21st@gmail.com');
        $this->assign('vo',$vo);
        $obj    =    (object)$vo;
        $this->assign('obj',$obj);
        $this->assign('array',array(5,260,13,7,40,50,2,1));
        $this->assign('num1',6);
        $this->assign('num2',2);
        $this->assign('num',6);
        $this->display();
    }
} 
?>

(2) The following demonstrates some basic usage of variables, constants and arrays assigned by the above controller to the template

Universal variable output

num1:{$num1}

Object output

id:{$obj:id}

name:{$obj:name}

Array output

id:{$vo['id']}

name:{$vo['name']}

Automatically determine array and object output

id:{$vo.id}

name:{$vo.name}

System constant output (system constants do not need to be assigned in the controller)

{$Think.now|date='Y-m-d H:i:s',###}

{$Think.server.PHP_SELF}

{$Think.session.name}

Use functions for variables (this can be built-in functions or custom functions)

{$vo.name|strtolower|ucwords}

Foreach output


{$key}:{$item}

The following example uses loop tags, Switch tags, and comparison tags


[{$i}]
Even rows
Odd rows
{$val} is greater than 5

{$val} is greater than 15

{$val} is less than 10


data{$val}
data{$val}
data{$val}
Other data is {$val}

The output result is similar to:

[1] Odd numbered lines 5 less than 10 length 1
[2] Even lines 260 is greater than 5 260 is greater than 15 The length is 3
[3] Odd lines 13 is greater than 5 and length is 2
[4] Even lines 7 is greater than 5, 7 is less than 10, length is 1
[5] Odd lines 40 greater than 5 40 greater than 15 length 2
[6] Even lines 50 is greater than 5 50 is greater than 15 length is 2
[7] Odd lines 2 less than 10 and length 1
[8] Even lines 1 is less than 10 and length is 1

ThinkPHP built-in template engine comparison tag

greater than 3
less than 3

The output result is similar to:

Greater than 3
Less than 3
Conditional judgment


{$num} is greater than 5

{$num} is greater than 3
Others{$num}

The output result is similar to:

6 is greater than 5

Articles you may be interested in

  • The last record to determine the volist loop in thinkphp template
  • System variables commonly used in Thinkphp templates Summary
  • How to set the jump waiting time for thinkphp page jump (successerror)
  • Summary of query skills in ThinkPHP
  • Full analysis of Thinkphp internal function ADSLCFUI shortcut method
  • How to turn off caching in thinkphp
  • php statistics search engine access records
  • thinkphp prints the last sql statement

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764131.htmlTechArticleThinkPHP’s built-in template engine is an independently innovative XML compilation template engine. Let’s share some of ThinkPHP’s built-in templates through a case. The usage of template tags commonly used by template engines includes...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn