Django CMS - check if placeholder is empty

后端 未结 5 2007
遥遥无期
遥遥无期 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:26

    Here's a very compact solution.

    Template filter:

    @register.filter('placeholder_is_empty')
    def placeholder_is_empty(request, slot):
        page = request.current_page
        placeholder = page.placeholders.get(slot=slot)
        return placeholder.cmsplugin_set.exists()
    

    Usage in template:

    {% if request|placeholder_is_empty:'myplaceholder' %}
        

    Here comes some content...

    {% endif %}

提交回复
热议问题