什么是 Smarty?
为什么使用它?
用例和工作流程
语法对比
模板继承
最佳做法
速成课程
所有 Smarty 模板标记都包含在定界符内。默认情况下,这些定界符是 {
和 }
, 但它们可以更改。
对于本手册中的示例,我们假设您正在使用默认定界符。在 Smarty 中,定界符之外的所有内容都显示为静态内容或未更改的内容。当 Smarty 遇到模板标记时,它会尝试解释它们,并在适当位置显示适当的输出。
模板注释用星号括起来,并且像这样用定界符标记括起来
{* this is a comment *}
Smarty 注释不会显示在模板的最终输出中,这与 <!-- HTML 注释 -->
不同。这些注释适用于在模板中做内部笔记,没人看得见 ;-)
示例 3.1 模板中的注释
{* I am a Smarty comment, I don't exist in the compiled output *} <html> <head> <title>{$title}</title> </head> <body> {* another single line smarty comment *} <!-- HTML comment that is sent to the browser --> {* this multiline smarty comment is not sent to browser *} {********************************************************* Multi line comment block with credits block @ author: [email protected] @ maintainer: [email protected] @ para: var that sets block style @ css: the style output **********************************************************} {* The header file with the main logo and stuff *} {include file='header.tpl'} {* Dev note: the $includeFile var is assigned in foo.php script *} <!-- Displays main content block --> {include file=$includeFile} {* this <select> block is redundant *} {* <select name="company"> {html_options options=$vals selected=$selected_id} </select> *} <!-- Show header from affiliate is disabled --> {* $affiliate|upper *} {* you cannot nest comments *} {* <select name="company"> {* <option value="0">-- none -- </option> *} {html_options options=$vals selected=$selected_id} </select> *} </body> </html>