smarty模板注释

smarty模板引擎的使用之模板注释

Smarty是一种从程序逻辑层(php)抽出外在(html/css)描述的PHP框架,这意味着php代码只负责逻辑应用,从外在描述中分离了出来。


模板注释被*星号包围,而两边的星号又被定界符包围,例如 {* this is a comment *}
smarty注释不会在模板文件的最后输出中出现,这与<!-- HTML 注释-->不同(译注:html注释在页面源码中可见,而smarty注释则不能)。这点非常有用,试想,注释只存在于模板里面,而在输出的页面中谁也看不见:)。

例 3-1.模板注释 {* 我是Smarty 注释, 在编译输出后我并不存在 *}
<html>
<head>
<title>{$title}</title>
</head>
<body>
{* 另一个smarty 单行注释 *}
<!-- HTML comment that is sent to the browser -->
{* 这是个smarty
注释,它不会
发送到浏览器
*}
{*********************************************************
带说明块的多行注释块
@ author: bg@example.com
@ maintainer: support@example.com
@ para: var that sets block style
@ css: the style output
**********************************************************}
{* 带主logo等的头文件 *}
{include file='header.tpl'}

{* Dev 注释: $includeFile变量由foo.php脚本赋值而来 *}
<!-- 显示主内容块 -->
{include file=$includeFile}
{* <select>块是多余的 *}
{*
<select name="company">
{html_options options=$vals selected=$selected_id}
</select>
*}
<!-- 关闭从子公司显示头信息 -->
{* $affiliate|upper *}
{* 不能嵌套注释 *}
{*
<select name="company">
{* <option value="0">-- none -- </option> *}
{html_options options=$vals selected=$selected_id}
</select>
*}
</body>
</html>

相关推荐

暂无推荐

评论/留言