2013-05-26 85 views
1

的循環,我想寫,如果條件與或條件:想寫一個或條件,如果perl的模板工具包

[% IF bug.product == 'CustomerCare' or bug.product =='Alerts' or bug.product =='Chatlog' %] 
<tr><td colspan="2"> <h3 align="center">Have you verified the Checklist ?</h3></td></tr> 

<tr> 
    <td> 
     <input type="checkbox" id="chck1" name="greet" value="1" [% FOREACH gre = chk_greet%] checked [% END%] /> 
    </td> 

    <td> 
     <label for = "chck1"> Greet the customer ?</label> 
    </td> 
</tr> 

<tr> 
    <td> <input type="checkbox" id="chck2" name="issue_status" value="1" [% FOREACH iss = chk_issustat%] checked [% END%] /> 
    </td> 
    <td> <label for = "chck2">Issue under concern and its status (whether resolved or not)</label> </td> 
</tr> 

<tr> 
    <td> 
     <input type="checkbox" id="chck3" name="done_fix" value="1" [% FOREACH don = chk_done%] checked [% END%] [% END %]/> 
    </td> 
</tr> 

什麼是寫這種情況下正確的格式?

+0

是或可以放在條件之間嗎?是這樣的嗎? –

回答

2

如果值列表開始變得有點大,使用hashref是另一種方式來簡化這個邏輯 - 特別是如果你要結束了寫一遍又一遍又一遍。它也使得邏輯更清晰,更簡潔。

[%- # Do this once, near the top. 
    SET checklistable = { CustomerCare => 1, Alerts => 1, Chatlog => 1 }; -%] 

[%- # then later on, as required; 
    IF checklistable.item(bug.product); 
     .... 
    END; -%] 
4

閱讀the fine manual。它包括你的例子。

[% IF (bug.product == 'CustomerCare') || (bug.product =='Alerts') ... %] 
+1

謝謝...... :) –