2016-03-16 22 views
1

可能在樹枝語法中生成一條if語句,並根據結果以某種方式關閉html標記。例如:如果樹枝中的語句

<button name="button" class="btn btn-warning" 
    {% if someCondition == false %} 

     > {#if is false close the button tag#} 

     <i class="fa fa-gift"></i><strong> Welcome<br />Present</strong> 
    {% else %} 

     disabled="disabled">{#if is true disable the button tag and then close#} 

     <i class="fa fa-gift"></i> Welcome<br />Present 
    {% endif %} 
</button> 

在此先感謝。

-UPDATE-

對不起我犯了一個愚蠢的錯誤,我是在做正確的事情,但在錯誤的地方,這就是爲什麼它沒有我的網站上反映出來。還是要謝謝你(:

+0

the on ly的事情/區別是你想要做的是禁用按鈕,如果條件是假的? – Matteo

+1

我會刪除這個問題(:我在這個地方犯了一個錯誤,那就是我沒有看到它反映在我的網站上的原因,無論如何,謝謝 – OmarAguinaga

+0

hi omar別擔心,你解決了嗎?想更新你的問題? – Matteo

回答

1

您的代碼看起來正確

我的方式做到這一點:

<button name="button" class="btn btn-warning" {% if someCondition == true %} disabled="disabled" {% endif %}> 

    <i class="fa fa-gift"></i><strong> Welcome<br />Present</strong> 

</button> 

如果您需要添加強大的標籤,你可以添加一個類:

<button name="button" class="btn btn-warning" {% if someCondition == true %} disabled="disabled" {% endif %}> 

    <i class="fa fa-gift {% if someCondition == true %} strongClass {% endif %}"></i><strong> Welcome<br />Present</strong> 

</button> 

你可以這樣做:

{% if someCondition == true %} 
    <button name="button" class="btn btn-warning" disabled="disabled"> 
     <i class="fa fa-gift"></i><strong> Welcome<br />Present</strong> 
    </button> 
{% else %} 
    <button name="button" class="btn btn-warning"> 
     <i class="fa fa-gift"></i>Welcome<br />Present 
    </button> 
{% endif %}