Django CMS 管理模板页面中的占位符

标签 django django-templates django-cms

我希望得到您在两点上的帮助:

首先,我创建一些默认页面的模板,例如: “Home.html、work-with-us.html”等

我的目标是简化网站负责人的工作。他们不必学习如何管理占位符内的插件。

因此,我创建了一些像这样的占位符,例如“workwithus.html”:

{% extends "base.html" %}
{% load cms_tags staticfiles sekizai_tags menu_tags %}
{% block content %}
<div class="container">

    <div class="col-xs-12">
        {% placeholder "image-full" %}
    </div>

    <div class="col-md-12">
        {% placeholder "text-platform" %}
    </div>
</div>
{% endblock content %}

我是这样管理插件的:

CMS_PLACEHOLDER_CONF = {
'image-full': {
    'plugins': ['FilerImagePlugin'],
    'name': gettext("Image full page"),
    'default_plugins': [
        {
            'plugin_type': 'FilerImagePlugin',
            'values': {
            },
        },
    ],
    'limits': {
        'global': 1,
        'FilerImagePlugin': 1,
    },
},

等等

问题是,我不能在同一个模板中多次使用相同的占位符。如果当我制作占位符“img-full-width”时我可以多次调用它,那就太好了。 你对此有什么想法吗?一种比创建“img-full-2”、“img-full-3”等更合适的方法。

第二个问题: 是否可以添加多个 default_plugins ?实在是让我很烦恼……

提前非常感谢你们!

最佳答案

您可以拥有任意数量的插件 default_plugins

参见http://django-cms.readthedocs.org/en/support-3.0.x/reference/configuration.html#placeholder-default-plugins

You can specify the list of default plugins which will be automagically added when the placeholder will be created (or rendered).

如果您对必须为每个占位符重新定义 CMS_PLACEHOLDER_CONF 感到烦恼,您始终可以在 CMS_PLACEHOLDER_CONF block 之前定义一个通用配置:

img_fullwidth_conf = {
    'plugins': ['FilerImagePlugin', 'TextPlugin'],
    'name': gettext("Image full page"),
    'default_plugins': [
        {
            'plugin_type': 'FilerImagePlugin',
            'values': {
            },
        },
        {
            'plugin_type': 'TextPlugin',
            'values': {
                'body': '<p>Write here...</p>'
            },
        },
    ],
}

CMS_PLACEHOLDER_CONF = {
    'img-full-1': img_fullwidth_conf,
    'img-full-2': img_fullwidth_conf,
    'img-full-3': img_fullwidth_conf,

}

关于Django CMS 管理模板页面中的占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29119430/

相关文章:

Django上下文处理器: Is it possible to access current context in ContextProcessor?

python - Django REST 框架和文件上传(数据 URI)

python - Django:如何使按钮在按下后消失/禁用?

python - Django 有自动排序模型字段的方法吗?

带有冲突 URL 的 Django-CMS AppHooks?

python - 带列表的 Django 过滤器过滤器

python - 获取某些值以 django 形式出现

python - 如何在 Django 模板中使用 'is not None'?

Django CMS 自定义插件 - 如何处理翻译

python - 由于 "IntegrityError: duplicate key value violates unique constraint",无法在 django-cms 上发布页面