有三种布局模板的支持方式:
第一种方式:全局配置方式
这种方式仅需在项目配置文件中添加相关的布局模板配置,就可以简单实现模板布局功能,比较适用于全站使用相同布局的情况,需要配置开启LAYOUT_ON参数(默认不开启),并且设置布局入口文件名LAYOUT_NAME(默认为layout)。
‘LAYOUT_NAME’=>’layout’,
开启LAYOUT_ON后,我们的模板渲染流程就有所变化,例如:
Public function add() {
$this->display(‘add’);
}
}
在不开启LAYOUT_ON布局模板之前,会直接渲染Tpl/User/add.html模板文件,开启之后,首先会渲染Tpl/layout.html模板,布局模板的写法和其他模板的写法类似,本身也可以支持所有的模板标签以及包含文件,区别在于有一个特定的输出替换变量{__CONTENT__},例如,下面是一个典型的layout.html模板的写法:
{__CONTENT__}
<include file=”Public:footer” />
读取layout模板之后,会再解析User/add.html模板文件,并把解析后的内容替换到layout布局模板文件的{__CONTENT__}特定字符串。
当然可以通过设置来改变这个特定的替换字符串,例如:
但是一个布局模板同时只能有一个特定替换字符串。
采用这种布局方式的情况下,一旦User/add.html模板文件或者layout.html布局模板文件发生修改,都会导致模板重新编译。
如果需要指定其他位置的布局模板,可以使用:
就表示采用Tpl/Layout/layoutname.html作为布局模板。
如果某些页面不需要使用布局模板功能,可以在模板文件开头加上{__NOLAYOUT__}字符串。
如果上面的User/add.html模板文件里面包含有{__NOLAYOUT__},则即使当前开启布局模板,也不会进行布局模板解析。
第二种方式:模板标签方式
这种布局模板不需要在配置文件中设置任何参数,也不需要开启LAYOUT_ON,直接在模板文件中指定布局模板即可,相关的布局模板调整也在模板中进行。
以前面的输出模板为例,这种方式的入口还是在User/add.html模板,但是我们可以修改下add模板文件的内容,在头部增加下面的布局标签(记得首先关闭前面的LAYOUT_ON设置,否则可能出现布局循环):
表示当前模板文件需要使用layout.html布局模板文件,而布局模板文件的写法和上面第一种方式是一样的。当渲染User/add.html模板文件的时候,如果读取到layout标签,则会把当前模板的解析内容替换到layout布局模板的{__CONTENT__}特定字符串。
一个模板文件中只能使用一个布局模板,如果模板文件中没有使用任何layout标签则表示当前模板不使用任何布局。
如果需要使用其他的布局模板,可以改变layout的name属性,例如:
还可以在layout标签里面指定要替换的特定字符串:
由于所有include标签引入的文件都支持layout标签,所以,我们可以借助layout标签和include标签相结合的方式实现布局模板的嵌套。例如,上面的例子
<div id=”main” class=”main” >
{__CONTENT__}
</div>
<include file=”Public:footer” />
在引入的header和footer模板文件中也可以添加layout标签,例如header模板文件的开头添加如下标签:
这样就实现了在头部模板中引用了menu布局模板。
也可以采用两种布局方式的结合,可以实现更加复杂的模板布局以及嵌套功能。
第三种方式:使用layout控制模板布局
使用内置的layout方法可以更灵活的在程序中控制模板输出的布局功能,尤其适用于局部需要布局或者关闭布局的情况,这种方式也不需要在配置文件中开启LAYOUT_ON。例如:
Public function add() {
layout(true);
$this->display(‘add’);
}
}
表示当前的模板输出启用了布局模板,并且采用默认的layout布局模板。
如果当前输出需要使用不同的布局模板,可以动态的指定布局模板名称,例如:
Public function add() {
layout(‘Layout/newlayout’);
$this->display(‘add’);
}
}
或者使用layout方法动态关闭当前模板的布局功能(这种用法可以配合第一种布局方式,例如全局配置已经开启了布局,可以在某个页面单独关闭):
Public function add() {
layout(false); // 临时关闭当前模板的布局功能
$this->display(‘add’);
}
}
总结
三种模板布局方式中,第一种和第三种是在程序中配置实现模板布局,第二种方式则是单纯通过模板标签在模板中使用布局。具体选择什么方式,需要根据项目的实际情况来了。
波比源码 » ThinkPHP3.1快速入门(15)模板布局
buy levaquin generic purchase levofloxacin generic
alendronate 35mg generic order generic alendronate 35mg pepcid for sale
cialis 40mg over the counter price cialis buy sildenafil pills
cheap cialis pills tadalafil 40mg pill buy anafranil 25mg pill
buy aralen online cenforce order olumiant 4mg usa
cheap clomid 50mg casino free spin world tavern poker online
cialis cheap sildenafil over counter sildenafil next day delivery
buy aristocort 10mg generic buy loratadine without prescription purchase clarinex pills
purchase zantac online cheap celebrex uk buy celebrex 200mg sale
online casino roulette online gambling real money cialis 5mg sale
buy desyrel 100mg buy aurogra 100mg online cheap sildenafil 100mg cost
sildenafil overnight estradiol pills lamotrigine online
casino slot buy stromectol 3mg buy provigil 200mg generic
cheap deltasone 10mg purchase mebendazole vermox 100mg tablet
adalat 30mg cost fexofenadine 120mg uk order fexofenadine 180mg pill
buy generic altace 5mg buy ramipril 5mg generic cost arcoxia
9Вє – Maldonado – O zagueiro e volante chileno foi contratado pelo Tricolor em 2000, quando o clube gastou 8,5 milhГµes de euros (15,6 milhГµes de reais Г Г©poca), para tirar o jogador do Colo-Colo Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information. O Rubro-Negro do Rio de Janeiro terminou o primeiro tempo com mais posse de bola e finalizações. A primeira oportunidade do Leão veio aos 47 minutos, quando Pedro tocou contra o próprio gol em cobrança de falta lateral e obrigou o goleiro Diego Alves a colocar para escanteio. Porém, o placar se manteve até o intervalo.
https://miriam.net.pl/community/profile/svenjamison873/
Mas ainda no primeiro tempo, novamente pГЄnalti. Dagson fez o terceiro com uma cobranГ§a cavadinha aos 44 minutos. JГЎ aos 5 minutos do segunto tempo, TarcГsio balanГ§ou a rede e fez o segundo dos mandantes. Mas ainda no primeiro tempo, novamente pГЄnalti. Dagson fez o terceiro com uma cobranГ§a cavadinha aos 44 minutos. JГЎ aos 5 minutos do segunto tempo, TarcГsio balanГ§ou a rede e fez o segundo dos mandantes. Apenas a Rede Globo manteve os direitos de transmissão da competição. Os jogos serão transmitidos na TV aberta pela Globo nas quartas e domingos, além dos canais fechados da emissora: SporTV e Premiere, com transmissão integral. Notícia em constante atualização até o final da rodada
order temovate cream order buspar 5mg generic buy amiodarone 200mg sale
buy digoxin pill molnupiravir medication molnunat 200 mg sale
carvedilol 6.25mg ca order amitriptyline pills amitriptyline for sale online
order indomethacin sale cenforce 100mg oral order cenforce 50mg for sale
pamelor 25mg cost generic nortriptyline 25mg purchase paroxetine for sale
order famotidine 40mg generic order remeron 15mg pill mirtazapine order
requip 1mg cost buy ropinirole 1mg for sale labetalol 100mg for sale
cost fenofibrate 200mg best viagra sites online sildenafil 50mg tablet
order esomeprazole 40mg pills nexium 20mg price lasix sale
Spain – Primera RFEF – Group 2 Ahead of the 2023 Supercoppa Italiana between Milan and Inter, we take a deep dive into everything there is to know about the Italian Super Cup. While the form book is one that is often thrown out of the window in a competition like the Premier League, it is always worth studying the form of the two teams along with which way historic results have gone. Many correct score tips will delve into the record books before posting their correct score predictions. However, just because a side has beaten their opponent 2-1 in four of their last 10 meetings going back 20 years does not mean they will do it again. Ensure you are not following correct score tips from a lazy writer that has not done their research properly or, similarly, don’t curtail your own chances of winning by not doing the relevant research before you place your money.
https://www.udrpsearch.com/user/rebeccagreen
Claiming that soccer predictions are guaranteed are not our thing. And to clear this out: nobody should claim something like that. Services that say their betting predictions are guaranteed do not properly stand behind their claim as they do not refund your staked money in case of loss nor do they offer to pay you the winnings if the prediction would have been won. The most many do is offer back the fee you paid to get the prediction, which is not really a guarantee for the quality of the soccer prediction. Bettors are probably not strange with this content, which provides trustworthy statistics and information for football pre-matches, allowing them to place more informed and accurate bets. Betimate always creates detailed match previews with comprehensive stats and analysis to help readers make more informed betting decisions.
provigil 200mg ca stromectol 12mg pills phenergan order
ivermectin 12 mg without prescription purchase prednisone online cheap brand prednisone 20mg
zofran canada ondansetron without prescription bactrim 960mg pill
cheap isotretinoin accutane 20mg pill buy zithromax 500mg generic