Smarty 基本语法(三)

Smarty 2.6.11 文档第二部分,模板设计者(Template Designers)
|-第三章,基本语法(Basic Syntax)

Math 数字
Math can be applied directly to variable values. 数字可以直接应用于变量中。
Example 3.6. math examples
例3.6 数字范例


{* some more complicated examples *}
{* 一些更复杂的例子 *}

{if ($foo+$bar.test%$baz*134232+10+$b+10)}


{assign var=”foo” value=”`$foo+$bar`”}

See also the {math} function for complex equations. 注意复杂等式中的函数{math}。
Escaping Smarty Parsing 避开Smarty解析
It is sometimes desirable or even necessary to have Smarty ignore sections it would otherwise parse. A classic example is embedding Javascript or CSS code in a template. The problem arises as those languages use the { and } characters which are also the default delimiters for Smarty. 有时候让Smarty忽略其他的对块的解析是需要的乃至必须的。一个经典的例子是在模板Javascript或者CSS代码中。问题在于这些语言使用{和}字符,而它们也是Smarty默认的定界符。
The simplest thing is to avoid the situation altogether by separating your Javascript and CSS code into their own files and then using standard HTML methods to access them. 完全避免这种情况最简单的方法,是通过分割你的Javascript和CSS代码到它们自己的文件中,使用标准的HTML方法访问它们。
Including literal content is possible using {literal} .. {/literal} blocks. Similar to HTML entity usage, you can use {ldelim},{rdelim} or {$smarty.ldelim} to display the current delimiters. 使用{literal} .. {/literal}块包含文字内容是可以的,像HTML实体使用,你可以使用{ldelim}、{rdelim}或者{$smarty.ldelim}来显示当前的定界符。
It is often convenient to simply change Smarty’s $left_delimiter and $right_delimiter. 简单地改变Smarty的$left_delimiter和$right_delimiter是非常方便的。
Example 3.7. changing delimiters example
例3.7 改变定界符范例

left_delimiter = ‘‘;
$smarty->assign(‘foo’, ‘bar’);


Where example.tpl is: example.tpl代码:
See also escape modifier. 注意修改的地方。



您的电子邮箱地址不会被公开。 必填项已用*标注