2016-04-04 11 views
0

Django CMSのページに追加されたすべてのプラグインを特定のHTMLでラップしたいと思います。だから、テンプレートDjango CMSですべてのプラグインを個別にラップします

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

そして

<p>Lorem ipsum</p> 

<p>dolor sit amet</p> 

は、実際にこのようになりますページとしてレンダリングするために言うようにレンダリングするページのTextPlugin要素で始まる:

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

I djangocms-cascadeを見ましたが、私が探しているものを正確に提供していないようで、マイグレーションは私のdjango-cms 3.2.1で失敗します。

答えて

3

django-cmsのプラグインプロセッサを見てみましょう。あなたのsettings.pyでhttp://docs.django-cms.org/en/3.2.2/how_to/custom_plugins.html#plugin-processors

を参照してください:

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)