Embedding Vars in Double Quotes
Smarty will recognize assigned variables embedded in double quotes so long as
the variables contain only numbers, letters, underscores and brackets [].
With any other characters (period, object reference, etc.) the variable must
be surrounded by backticks. You cannot embed modifiers, they must always be
applied outside of quotes.
如果變數名稱只有包含數字、英文字母、底線與中括號 [] 的話,則 Smarty 可識別出
雙引號內的變數。如果有其他的字元的話(如句號、參照物件等等的)此變數則必須在中括號內
。你不能在引號內加入修飾字元,這些修飾字元必須在引號外。
Example 3-5. embedded quotes syntax SYNTAX EXAMPLES:
{func var="test $foo test"} <-- sees $foo
{func var="test $foo_bar test"} <-- sees $foo_bar
{func var="test $foo[0] test"} <-- sees $foo[0]
{func var="test $foo[bar] test"} <-- sees $foo[bar]
{func var="test $foo.bar test"} <-- sees $foo (not $foo.bar)
{func var="test `$foo.bar` test"} <-- sees $foo.bar
{func var="test `$foo.bar` test"|escape} <-- modifiers outside quotes!
PRACTICAL EXAMPLES:
{include file="subdir/$tpl_name.tpl"} <-- will replace $tpl_name with value
{cycle values="one,two,`$smarty.config.myval`"} <-- must have backticks |
|