2013-02-20 69 views
0

我可以通过执行获得当前页面的标题输出:对模板中的标题有条件?

{% block title %}{% endblock %} 

但是,我怎么能在有条件使用它?这似乎并不奏效:

{% if title == "Bla" %} 
    doing some stuff! 
{% endif %} 

谢谢!

+0

为什么不把它写在意见? – iMom0 2013-02-20 00:47:40

+0

在这种情况下,标题是模板中的块。如果你没有在你的视图中设置变量'title',你将无法在条件中使用这个 – oleron 2013-02-20 00:50:59

回答

1

Your current syntax is correct according to the Django docs,仔细检查title是否具有您认为它的价值。

==操作
平等。例如:

{% if somevar == "x" %}
        This appears if variable somevar equals the string "x"
{% endif %}

+0

没错,我很愚蠢,我忘记了上下文! :d – FLX 2013-02-20 01:02:25