这种结构在php程序里边来控制再简单不过,但再模板中的话,它要求if必须成对出现!!!

解决方案 »

  1.   

    贴篇教程:
    if,elseif,else
    if statements in Smarty have much the same flexibility as php if statements, with a few added features for the template engine. Every if must be paired with an /if. else and elseif are also permitted. "eq", "ne","neq", "gt", "lt", "lte", "le", "gte" "ge","is even","is odd", "is not even","is not odd","not","mod","div by","even by","odd by","==","!=",">", "<","<=",">=" are all valid conditional qualifiers, and must be separated from surrounding elements by spaces.Example 7-11. if statements{if $name eq "Fred"}
        Welcome Sir.
    {elseif $name eq "Wilma"}
        Welcome Ma'am.
    {else}
        Welcome, whatever you are.
    {/if}{* an example with "or" logic *}
    {if $name eq "Fred" or $name eq "Wilma"}
        ...
    {/if}{* same as above *}
    {if $name == "Fred" || $name == "Wilma"}
        ...
    {/if}{* the following syntax will NOT work, conditional qualifiers
       must be separated from surrounding elements by spaces *}
    {if $name=="Fred" || $name=="Wilma"}
        ...
    {/if}
    {* parenthesis are allowed *}
    {if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
        ...
    {/if}{* you can also embed php function calls *}
    {if count($var) gt 0}
        ...
    {/if}{* test if values are even or odd *}
    {if $var is even}
        ...
    {/if}
    {if $var is odd}
        ...
    {/if}
    {if $var is not odd}
        ...
    {/if}{* test if var is divisible by 4 *}
    {if $var is div by 4}
        ...
    {/if}{* test if var is even, grouped by two. i.e.,
    0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
    {if $var is even by 2}
        ...
    {/if}{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
    {if $var is even by 3}
        ...
    {/if}
     
      

  2.   

    如果你是想直接把something改写成
     {if smt1}abc{else}{/if}
     {if smt2}abc{else}{/if}
     {if smt3}abc{else}{/if}
    那么你一开始不就写好了吗?如果你是想通过变量赋值把something变成控制语句,那么是不可以的
    因为没有的编译过程我理解你需要的是后一种做法,所以在原先的帖子里才让你将php代码写进去
      

  3.   

    其实不是变量smt的问题,跟PHP程序没多大关系,这个问题纯粹是如何通过控制语句来控制模板中表格的显示,它所控制表格的显示结构就是这样的:
    {if smt1}
    表格1
    {else *条件不成立*}
    表格2
    {/if}
    但是我要在表格1的位置,也就是当执行if时,再添加其他的控制语句来控制其他表格的显示!
      

  4.   

    在表格1的位置继续写成对的{if}{/if}就行了。