Smarty Common Operator Learning notes

Source: Internet
Author: User
Tags abs foreach

This is for backup.
eq = Equal Equal
NEQ = Not equal is not equal to
GT = Greater than greater than
lt = Less than less than
LTE = Less than or equal less than or equal
GTE = great than or equal is greater than or equal to
Not non-
MoD Take surplus
Div by IS ... Except
Is even is an even
is odd are odd
Are not even are not even
Are not odd are not odd

{$variable} variable

{if $grade eq "one"}
Hello one.
{ElseIf $grade eq "Two"}
Hello Teo.
{Else}
Hello anything.
{/if}

{literal}
<script language=javascript>

<!--
function Isblank (field) {
if (Field.value = = ")
{return false;}
Else
{
Document.loginform.submit ();
return true;
}
}
-->
</script>
{/literal}

{foreach from= $specification item=spec Key=spec_key}
{$spec. name}:<br/>
{if $spec. Attr_type eq 1}
{foreach from= $spec. Values Item=value Key=key}
<input type= "Radio" name= "spec_{$spec _key}" value= "{$value. ID}" id= "spec_value_{$value. ID}" {if $key eq 0}checked{/ If}/>
{$value. Label} [{if $value. Price GT 0}{$lang. Plus}{elseif $value. 0}{$lang. minus}{/if} {$value. format_price|abs}]<br/>
{/foreach}
<input type= "hidden" name= "Spec_list" value= "{$key}"/>
{Else}
{foreach from= $spec. Values Item=value Key=key}
<input type= "checkbox" Name= "spec_{$spec _key}" value= "{$value. ID}" id= "spec_value_{$value. ID}"/>
{$value. Label} [{if $value. Price GT 0}{$lang. Plus}{elseif $value. 0}{$lang. minus}{/if} {$value. format_price|abs}]<br/>
{/foreach}
<input type= "hidden" name= "Spec_list" value= "{$key}"/>
{/if}
{/foreach}

{if $grade eq "one"}
Hello one.
{ElseIf $grade eq "Two"}
Hello Teo.
{Else}
Hello anything.
{/if}

{literal}
<script language=javascript>

<!--
function Isblank (field) {
if (Field.value = = ")
{return false;}
Else
{
Document.loginform.submit ();
return true;
}
}
-->
</script>
{/literal}

{foreach from= $specification item=spec Key=spec_key}
{$spec. name}:<br/>
{if $spec. Attr_type eq 1}
{foreach from= $spec. Values Item=value Key=key}
<input type= "Radio" name= "spec_{$spec _key}" value= "{$value. ID}" id= "spec_value_{$value. ID}" {if $key eq 0}checked{/ If}/>
{$value. Label} [{if $value. Price GT 0}{$lang. Plus}{elseif $value. 0}{$lang. minus}{/if} {$value. format_price|abs}]<br/>
{/foreach}
<input type= "hidden" name= "Spec_list" value= "{$key}"/>
{Else}
{foreach from= $spec. Values Item=value Key=key}
<input type= "checkbox" Name= "spec_{$spec _key}" value= "{$value. ID}" id= "spec_value_{$value. ID}"/>
{$value. Label} [{if $value. Price GT 0}{$lang. Plus}{elseif $value. 0}{$lang. minus}{/if} {$value. format_price|abs}]<br/>
{/foreach}
<input type= "hidden" name= "Spec_list" value= "{$key}"/>
{/if}
{/foreach}

Smarty Mathematical Operations


{$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 '"}

In the template

Mathematical operations can be applied directly to variables

$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 '"}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.