Django-CMS - Global placeholder?

被刻印的时光 ゝ 提交于 2019-12-10 04:35:06

问题


Is there any way to make global placeholder in my base template? I need it to be the same on every page (banners list). How can I do that?


回答1:


I usually create a page in my CMS that isn't published, but contains placeholders that I would like to use elsewhere (footer/headers) etc.

Make a new template extra_placeholders.html:

{% extends "base.html" %}
{% load cms_tags %}

{% block content %}
    {% placeholder "Banner-List" %}
{% endblock %}

add it to your settings:

CMS_TEMPLATES = (
    ('my/path/extra_placeholders.html', 'Extra Placeholder Page'),
    ...
)

now go to the admin and create the placeholder with whatever plugin you want. Then go to you base template (*base.html probably) from which all your other pages inherit and add this wherever you want the placeholder to appear:

{% load cms_tags %}
...
{% show_placeholder "Banner-List" "extra_placeholders" %}

You can read more about it in the docs


EDIT

As @José L. Patiño has mentioned in the comments, this solution is only necessary for those using django-cms < 3.0. For the newer version you can simply use the static_placeholder template tag




回答2:


There is the "static_placeholders" now, http://docs.django-cms.org/en/latest/reference/templatetags.html#static-placeholder

Sounds like it's what you needed way back when.




回答3:


You can use the following ways to create a global palceholder for all pages.

  1. create a place holder on the base page. {% Placeholder "footer"%}
  2. make the contents of the placeholder through django cms as home page
  3. then to display the same for each placeholder page, add {% show_placeholder "footer" "home"%}, this means displaying the newly created footer placeholder earlier from the home page,
  4. This will display the entire contents existing footer placeholders on the home page of all pages that use the template.
  5. but for the home page there will be two footer is displayed, to mengilangkannya, please do modifications to use CSS to hide the master placeholder.


来源:https://stackoverflow.com/questions/13368848/django-cms-global-placeholder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!