2017-04-13 71 views
0

我正在做的webapp瓶和我有以下選項卡的內容:使用Jinja2檢測活動選項卡?

<div class="tab-content"> 
    <div class="tab-pane fade in active" id="gable"> 
     {% include 'building_form.html' %} 
    </div> 
    <div class="tab-pane fade" id="shed"> 
     {% include 'building_form.html' %} 
    </div> 
    <div class="tab-pane fade" id="flat"> 
     {% include 'building_form.html' %} 
    </div> 
</div> 

代碼爲building_form.html是:

<form method="post" action=""> 
    {{ form.hidden_tag() }} 

    <div class="form-group label-floating"> 
     {{ wtf.form_field(form.width) }}<br> 
    </div> 
    <div class="form-group label-floating"> 
     {{ wtf.form_field(form.length) }}<br> 
    </div> 
    <div class="form-group label-floating"> 
     {{ wtf.form_field(form.bottom_height) }}<br> 
    </div> 
    <div class="form-group label-floating"> 
     {{ wtf.form_field(form.top_height) }}<br> 
    </div> 
    {% if ???? %} <!--What put here?--> 
    <div class="form-group label-floating"> 
     {{ wtf.form_field(form.ridge_height) }}<br> 
    </div> 
    {% endif %} 
<p><input type=submit value="Calcular"></p> 
</form> 

I'm只想渲染「的形式。當id =「gable」激活時,「ridge_height」。使用Jinja2可以做到這一點嗎?

+0

你設法解決這個問題? –

回答

0

你可以做一些類似於下面的事情,但它可能無法正常工作!當使用with包裝變量時,您可以將變量傳遞到包含變量。您可能需要設置所謂隱藏的另一個CSS類,如果你沒有一個已經,可以這樣進行:

.hidden { 
    display: none; 
} 

{% with gable = True %} 
    {% include 'building_form.html' %} 
{% endwith %} 

然後內building_form:

<div class="form-group label-floating {{ '' if gable == True else 'hidden' }}"> 
    {{ wtf.form_field(form.ridge_height) }}<br> 
</div> 
相關問題