Thinkphp5.0第五篇

原樣輸出

使用literal標籤防止模板標籤被解析php

例如html

{literal}
        {$name}<br/>
{/literal}

模板單行註釋

{//註釋內容}

多行註釋

{/*註釋內容*/}

模板佈局

全局配置方式

config.php裏面模板設置相關加入以下內容app

'layout_on' => true,
        'layout_name' => 'layout',

在view裏面新增layout.html佈局

<html>
    <head>
        <meta charset="utf-8"/>
        <title>模板佈局</title>
    </head>
    <body>
        <div style="width:100%;height:100px; background-color:red;"> </div>
        {__CONTENT__}
        <div style="width: 100%; height:100px;background-color:blue;">

        </div>
    </body>
</html>
{__CONTENT__}裏面包含index的內容

模板標籤方式

配置文件裏面不用設置僅僅在index.html裏面加入一個code

{layout name="模板名稱"/}

使用layout控制模板佈局

htm

模板繼承

在view下建立的模板base.html主要是{block}繼承

<html>
    <head>
        <meta charset="utf-8"/>
        <title>模板繼承</title>
    </head>
    <body>
            {block name="head"}
            <div style="width: 100%;height: 100px; background-color: yellow">
                這是基礎模板的頭部信息
            </div>
            {/block}<br/>
            {block name="footer"}
            <div style="width: 100%;height: 100px;background-color: green">
                這是基礎模板的底部信息
            </div>
            {/block}
    </body>
</html>

而後在index.html下utf-8

使用it

{extend name="base" /}

便可繼承從而渲染,不事後面的內容會被覆蓋,若是不想被覆蓋在index.html裏面不想被覆蓋的block後面加一個io

{__block__}便可

注意區塊以外的內容是不會被渲染的

包含文件

{include file='模版文件1,模版文件2,...' }

例如在一個html裏面包含一個html並進行渲染

{include file='../application/index/view/index/lang.html'}
相關文章
相關標籤/搜索