Skip to content

Create Dummy Plugins

Alexandre Costa edited this page Aug 18, 2024 · 2 revisions

A Dummy plugin is a plugin that does "nothing". It is possible that some plugins are not needed in the current context, but they are required to build the plugin tree. In this case, you can create a dummy plugin that simply nests other plugins.

Example: Use Case with the Module Plugin

For example, let's say you are using the library django CMS Modules. This library provides a plugin called Module that adds a nested copy of a previously created plugin tree. It is useful when you want to reuse a plugin tree in multiple places. The Module plugin itself works as a container, and it does not have any content.

When exporting your plugins, you may not want to handle the Module plugin, maybe because the target CMS does not have it installed, or because the target CMS has different modules saved that wouldn't be compatible with the exported Module plugin. In this case, you can create a dummy plugin that nests the plugins inside the Module plugin.

In the image below, we created a Dummy Plugin called Wrapper, that doesn't have any required fields. Plugie converts Module to Wrapper, and then continues importing the nested tree.

A Module plugin converted to a Dummy Plugin named Wrapper

Steps to Create a Dummy Plugin

Creating a dummy plugin is just like creating any other plugin. The only difference is that this plugin must not have any required fields. Follow the instructions in the Django CMS documentation to create a plugin.

Here is an example of a dummy plugin that nests other plugins:

# myapp/components/cms_plugins/dummy.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from myapp.components.models.dummy import MyDummyModel
from django.utils.translation import ugettext as _

@plugin_pool.register_plugin 
class MyDummyPlugin(CMSPluginBase):
    model = MyDummyModel
    module = -('Dummies')
    name = _('My Dummy Plugin')
    render_template = "render_component.html"
    allow_children = True
# myapp/components/models/dummy.py
from django.db import models
from cms.models import CMSPlugin


class MyDummyModel(CMSPlugin):
    dummy_id = models.CharField(max_length=256, blank=True, default='')

    def __str__(self):
        return f'#{self.dummy_id}'

Converting Plugins to a Dummy Plugin

If you already have a dummy plugin, Plugie allows you to easily specify which plugins you want to convert. In the plugie_config.json file, you can add the key dummy_plugins with an object that contains a list of the source plugins you want to convert and the target dummy plugin.

{
    ...
    "dummy_plugins": {
        "source": ["MySourcePlugin, Module"], # etc...
        "target": "MyDummyPlugin"
    }
}

Check the documentation for more information on how to create and use the plugie_config.json file.