smarty文件包含和模板继承

原创 2019-01-19 12:41:28 233
摘要:文件包含:demo5.html:{include file = "public/title.html" assign = "title" brand = "华帝"}//include file = "public/title.html"这句是将title.html这个文件包含进来,即将title.html文件内容引用到

文件包含:

demo5.html:

{include file = "public/title.html" assign = "title" brand = "华帝"}//include file = "public/title.html"这句是将title.html这个文件包含进来,即将title.html文件内容引用到demo5.html文件中,assign = "title"是将引用进来的内容存到title变量中,brand = "华帝"是将变量brand的内容传给title.html中。

{$title}

title.html:

<h2>中消协向{$brand}发出约谈函</h2>

模板继承:

layout.html://父模板

...

<title>{block  name = "title"}页面标题{/block}</title>//block标签之间的为父模板的区块

...

demo6.html//模板文件

{extends file = "layout.html"}//有点类似类,模板文件继承父模板,包含文件是include,继承是extends

{block name = "title"}//实例化父模板中的区块

...            //内容自己填写

{$smarty.block.parent}//也可以直接继承父模板的内容

{/block}


批改老师:查无此人批改时间:2019-01-19 13:48:06
老师总结:完成的不错,模版要多练习,学php最终目的,就是会模版,可以上手项目,加油。

发布手记

热门词条