【问题标题】:Django CMS manage placeholder in template pagesDjango CMS 管理模板页面中的占位符
【发布时间】:2015-05-21 01:58:21
【问题描述】:

我希望您能在两点上提供帮助:

首先,我正在创建一些默认页面的模板,例如: “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 ?真的很烦我……

非常感谢你们!

【问题讨论】:

    标签: django django-templates django-cms


    【解决方案1】:

    default_plugins 拥有任意数量的插件

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

    您可以指定默认插件的列表 在创建占位符时自动添加(或 渲染)。

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

    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,
    
    }
    

    【讨论】:

    • 奇怪,我做了多个默认设置,但没有用。我一定是打错了,我再试一次。我很欣赏 CMS_PLACEHOLDER_CONF 的提示!非常感谢楼主!
    • 如果答案有帮助,别忘了您可以将此答案标记为已接受的答案:-)
    猜你喜欢
    • 2013-09-26
    • 2015-05-20
    • 2017-09-19
    • 2017-10-26
    • 2022-08-04
    • 1970-01-01
    • 2013-03-22
    • 2018-04-12
    • 2014-08-31
    相关资源
    最近更新 更多