Django CMS - 检查占位符是否为空 [英] Django CMS - check if placeholder is empty
本文介绍了Django CMS - 检查占位符是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用:
- DjangoCMS 2.4
- Django 1.5.1
- Python 2.7.3
我想检查我的占位符是否为空。
I would like to check if my placeholder is empty.
<div>
{% placeholder "my_placeholder" or %}
{% endplaceholder %}
</div>
如果占位符为空,我不希望创建占位符之间的html。 p>
I don't want the html between the placeholder to be created if the placeholder is empty.
{% if placeholder "my_placeholder" %}
<div>
{% placeholder "my_placeholder" or %}
{% endplaceholder %}
</div>
{% endif %}
推荐答案
没有内置的方式在django-cms中这样做,所以你必须编写一个自定义的模板标签。在 django-cms
Google组中有一些旧的讨论:
There is no built-in way to do this at the moment in django-cms, so you have to write a custom template tag. There are some old discussions about this on the django-cms
Google Group:
- https://groups.google.com/forum/#!topic/django-cms/ WDUjIpSc23c /讨论
- https: //groups.google.com/forum/#!msg/django-cms/iAuZmft5JNw/yPl8NwOtQW4J
- https://groups.google.com/forum/?fromgroups=#!topic/django-cms/QeTlmxQnn3E
- https://groups.google.com/forum/#!主题/ django-cms / 2mWvEpTH0ns /讨论
- https://groups.google.com/forum/#!topic/django-cms/WDUjIpSc23c/discussion
- https://groups.google.com/forum/#!msg/django-cms/iAuZmft5JNw/yPl8NwOtQW4J
- https://groups.google.com/forum/?fromgroups=#!topic/django-cms/QeTlmxQnn3E
- https://groups.google.com/forum/#!topic/django-cms/2mWvEpTH0ns/discussion
根据第一次讨论中的代码,我已经放在一起以下Gist:
Based on the code in the first discussion, I've put together the following Gist:
- https://gist.github.com/timmyomahony/5796677
我使用如下: / p>
I use it like so:
{% load extra_cms_tags %}
{% get_placeholder "My Placeholder" as my_placeholder %}
{% if my_placeholder %}
<div>
{{ my_placeholder }}
</div>
{% endif %}
这篇关于Django CMS - 检查占位符是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文