Django CMS - check if placeholder is empty

后端 未结 5 2023
遥遥无期
遥遥无期 2021-02-14 04:16

I use:

  • DjangoCMS 2.4
  • Django 1.5.1
  • Python 2.7.3

I would like to check if my placeholder is empty.

{
5条回答
  •  不思量自难忘°
    2021-02-14 04:49

    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/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

    Based on the code in the first discussion, I've put together the following Gist:

    • https://gist.github.com/timmyomahony/5796677

    I use it like so:

    {% load extra_cms_tags %}
    {% get_placeholder "My Placeholder" as my_placeholder %}
    
    {% if my_placeholder %}
    
    {{ my_placeholder }}
    {% endif %}

提交回复
热议问题