使用Jinja2检测活动选项卡?
问题描述:
我正在做的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可以做到这一点吗?
答
你可以做一些类似于下面的事情,但它可能无法正常工作!当使用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>
你设法解决这个问题? –