在Django CMS中单独包装每个插件



我想用特定的HTML包装添加到Django CMS页面中的每个插件。因此,从模板开始

<body>
  {% block content %}{% endblock content %}
<body>

以及页面上呈现为的TextPlugin元素

<p>Lorem ipsum</p>

<p>dolor sit amet</p>

实际呈现为如下页面:

<body>
  <div class="wrapper"><p>Lorem ipsum</p></div>
  <div class="wrapper"><p>dolor sit amet</p></div>      
</body>

我看了一下djangocms级联,但它似乎并没有提供我想要的东西,而且在我的djangoCMS3.2.1上迁移失败了。

看看django-cms的插件处理器。看见http://docs.django-cms.org/en/3.2.2/how_to/custom_plugins.html#plugin-处理器

在您的设置中.py:

CMS_PLUGIN_PROCESSORS = (
    'yourapp.cms_plugin_processors.wrap_plugin',
)

在您的应用程序.cms_plugin_processors.py中:

from django.template import Context, Template
def wrap_plugin(instance, placeholder, rendered_content, original_context):
    t = Template('<div class="wrapper">{{ content|safe }}</div>')
    c = Context({
        'content': rendered_content
    })
    return t.render(c)

最新更新