How to add a plugin in a plugin Django CMS

I have create a plugin like plugin_pool. But I don't know how to add another plugin in this plugin.

Upvotes: 1

Views: 864

Answers (1)

markwalker_
markwalker_

Reputation: 12849

Your plugin needs to set the allow_children attribute, and then you can control what children the plugin can have, if you want to, by specifying plugin classes in a list of child_classes as you'll see below.

from .models import ParentPlugin, ChildPlugin

@plugin_pool.register_plugin
class ParentCMSPlugin(CMSPluginBase):
    render_template = 'parent.html'
    name = 'Parent'
    model = ParentPlugin
    allow_children = True  # This enables the parent plugin to accept child plugins
    # You can also specify a list of plugins that are accepted as children,
    # or leave it away completely to accept all
    # child_classes = ['ChildCMSPlugin']

    def render(self, context, instance, placeholder):
        context = super(ParentCMSPlugin, self).render(context, instance, placeholder)
        return context


@plugin_pool.register_plugin
class ChildCMSPlugin(CMSPluginBase):
    render_template = 'child.html'
    name = 'Child'
    model = ChildPlugin
    require_parent = True  # Is it required that this plugin is a child of another plugin?
    # You can also specify a list of plugins that are accepted as parents,
    # or leave it away completely to accept all
    # parent_classes = ['ParentCMSPlugin']

    def render(self, context, instance, placeholder):
        context = super(ChildCMSPlugin, self).render(context, instance, placeholder)
        return context

Your parent plugin template then needs to render the children somewhere like this;

{% load cms_tags %}

<div class="plugin parent">
    {% for plugin in instance.child_plugin_instances %}
        {% render_plugin plugin %}
    {% endfor %}
</div>

The docs for it are on that page you've linked to;

http://docs.django-cms.org/en/latest/how_to/custom_plugins.html#nested-plugins

Upvotes: 1

Related Questions