1

I have written the simplest Django CMS plugin possible that allows children (I use Python 3.4.3, Django 1.7.10, Django CMS 3.1.3):

cms_plugins.py:

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool

class SamplePlugin(CMSPluginBase):
    allow_children = True
    render_template = "sample_plugin.html"

    def render(self, context, instance, placeholder):
        context['instance'] = instance
        return context

plugin_pool.register_plugin(SamplePlugin)

templates/sample_plugin.html:

{% load cms_tags %}

{% for plugin in instance.child_plugins %}{% render_plugin plugin %}{% endfor %}

I don't use a custom model, just render the child plugins.

I then opened a page in Structure mode and added one instance of that Sampe Plugin and a Style Plugin to a placeholder - so far, so good. I can edit both, of course there is not much to edit for my own plugin. When I now move the Style Plugin into my Sample Plugin, I can still edit the Style Plugin. Switching to content mode and inspecting the DOM, the plugins really are nested.

However, if I now refresh the page, something is clearly inconsistent:

  • the div corresponding to the Sample Plugin is empty in the DOM
  • in Structure mode, the nested Style Plugin no longer shows a context menu
  • double clicking it opens the parent Sample Plugin's editor (the DOM shows the parent's id in the iframe source. Manually changing that URL opens the right Editor)
  • the Style Plugin can no longer be moved around

A quick inspection of djangocms_style doesn't show any obvious differences that seem relevant to the problem. What's going on here?


I'm also getting stack traces similar to these, but they seem to be unrelated - it happens when adding any plugin - and don't disrupt anything else - no 503 or anything.

Silly Freak
  • 4,061
  • 1
  • 36
  • 58

1 Answers1

1

The problem seems to be in the template, it's supposed to be

{% for plugin in instance.child_plugin_instances %}

instead if

{% for plugin in instance.child_plugins %}

This seems to have changed between Django CMS 2.4 and 3.0: Compare the information on 2.4 and 3.0 (look at parent.html)

I have found it's not necessary to override render to add context['instance']; the Style Plugin doesn't do that either.

Silly Freak
  • 4,061
  • 1
  • 36
  • 58