Get Smarty


Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Shop for 2018 World Cup Football Boots Online sale at

Browse best 2018 world cup soccer cleats and shoes from



当你的模板多数使用了相同的头部和底部HTML代码,通常 会将它们分隔到单独的模板中,用 {include}来载入它们。 但如果头部HTML会根据页面的不同,而需要有不同的标题, 那么你需要在包含模板时设置标题为属性

Example 21.3. 传递标题到头部模板

mainpage.tpl - 当主体页面被渲染时, Main Page的标题值会被传递到 header.tpl,这样就可以被当作标题使用了。

{include file='header.tpl' title='Main Page'}
{* template body goes here *}
{include file='footer.tpl'}


archives.tpl - 当主体页面被渲染时, 页面标题会是Archives。 注意在下面例子中,我们使用了来自配置文件archives_page.conf的变量,替代硬编码的变量值。

{config_load file='archive_page.conf'}

{include file='header.tpl' title=#archivePageTitle#}
{* template body goes here *}
{include file='footer.tpl'}


header.tpl - 注意下面例子使用了 default的变量修饰器,当标题$title 变量未设置时,将显示Smarty News

<title>{$title|default:'Smarty News'}</title>





No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 20 plus 16? (Are you human?)