一聚教程网:一个值得你收藏的教程网站

热门教程

Smarty常用运算符学习笔记

时间:2022-06-25 02:17:23 编辑:袖梨 来源:一聚教程网

//这个是用来做备份的
eq = equal 相等
neq = not equal 不等于
gt = greater than 大于
lt = less than 小于
lte = less than or equal 小于等于
gte = great than or equal 大于等于
not 非
mod 取余
div by 被…除
is even 是偶数
is odd 是奇数
is not even 不是偶数
is not odd 不是奇数

{$variable} 变量

{if $grade eq "one"}
    hello one.
{elseif $grade eq "two"}
    hello teo.
{else}
    hello anything.
{/if}
 
{literal}
   
{/literal}
 
{foreach from=$specification item=spec key=spec_key}
{$spec.name}:

  {if $spec.attr_type eq 1}
    {foreach from=$spec.values item=value key=key}
   
    {$value.label} [{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if} {$value.format_price|abs}]

    {/foreach}
   
  {else}
    {foreach from=$spec.values item=value key=key}
    checkbox" name="spec_{$spec_key}" value="{$value.id}" id="spec_value_{$value.id}"/>
    {$value.label} [{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if} {$value.format_price|abs}]

    {/foreach}
   
  {/if}
{/foreach}

{if $grade eq "one"}
    hello one.
{elseif $grade eq "two"}
    hello teo.
{else}
    hello anything.
{/if}
 
{literal}
   
{/literal}
 
{foreach from=$specification item=spec key=spec_key}
{$spec.name}:

  {if $spec.attr_type eq 1}
    {foreach from=$spec.values item=value key=key}
   
    {$value.label} [{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if} {$value.format_price|abs}]

    {/foreach}
   
  {else}
    {foreach from=$spec.values item=value key=key}
   
    {$value.label} [{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if} {$value.format_price|abs}]

    {/foreach}
   
  {/if}
{/foreach}

Smarty数学运算

 
{$foo+1}

{$foo*$bar}
 
{* some more complicated examples *}
 
{$foo->bar-$bar[1]*$baz->foo->bar()-3*7}

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

{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}

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

在模板中

数学运算可以直接应用到变量上

  $smarty->assign('a',11);
 $smarty->display('111.html');

 {$a*4}

{$foo+1}{$foo*$bar} {* some more complicated examples *} {$foo->bar-$bar[1]*$baz->foo->bar()-3*7}{if ($foo+$bar.test%$baz*134232+10+$b+10)}{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}{assign var="foo" value="`$foo+$bar`"}

热门栏目