Smarty学习之基础语法

1)注释

{* this is a comment *}

2)变量

{$foo}   {$foo[4]}   {$foo.bar} {$foo.$bar} {$foo->bar}    {$foo->bar()}

{#foo#} {$smarty.config.foo}   {"foo"}

3) 函数

 

{config_load file='colors.conf'}
{include file='footer.tpl' ad=$random_id}
{include file=#includeFile# title='Smarty is cool'}

4)嵌入变量

{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!

5)改变smarty分离符号

<?php
$smarty->left_delimiter = '<!--{';
$smarty->right_delimiter = '}-->';
$smarty->assign('foo', 'bar');
$smarty->assign('name', 'Albert');
$smarty->display('example.tpl');
?>


Welcome <!--{$name}--> to Smarty
<script language="javascript">
var foo = <!--{$foo}-->;
function dosomething() {
alert("foo is " + foo);
}
dosomething();
</script>

你可能感兴趣的:(Smarty学习之基础语法)