Django-CMS-全球占位符? [英] Django-CMS - Global placeholder?

查看:94
本文介绍了Django-CMS-全球占位符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在基本模板中创建全局占位符?我需要在每个页面(横幅列表)上都一样. 我该怎么办?

解决方案

我通常在CMS中创建一个未发布的页面,但其中包含我想在其他地方(页脚/页眉)使用的占位符.

制作新模板 extra_placeholders.html :

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

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

将其添加到您的设置:

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

现在转到管理员并使用所需的任何插件创建占位符.然后转到基本模板(可能是 * base.html ),所有其他页面都将从该模板继承而来,并将其添加到您希望占位符出现的位置:

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

您可以在文档


编辑

正如@JoséL.Patiño在评论中提到的那样,此解决方案仅对使用django-cms< 3.0.对于较新的版本,您只需使用 static_placeholder 模板标记

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?

解决方案

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

这篇关于Django-CMS-全球占位符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆