【问题标题】:Wrap every plugin separately in Django CMS在 Django CMS 中分别包装每个插件
【发布时间】:2016-04-04 09:52:39
【问题描述】:

我想将添加到我的 Django CMS 中的页面的每个插件都包装在特定的 HTML 中。所以,从模板开始

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

页面上的 TextPlugin 元素呈现为say

<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-cascade,但它似乎并没有提供我正在寻找的东西,并且迁移在我的 django-cms 3.2.1 上失败。

【问题讨论】:

    标签: python django django-cms


    【解决方案1】:

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

    在你的 settings.py 中:

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

    在您的 yourapp.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)
    

    【讨论】:

      猜你喜欢
      • 2011-04-06
      • 2014-09-21
      • 1970-01-01
      • 2011-06-27
      • 2021-01-11
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多