fekioh
fekioh

Reputation: 996

Get plugin name for conditional rendering in django-cms templates

How can I get the plugin name, so I can do different things depending on it? In a situation of nested plugins, I have a block like this:

{% block section_content %}
    {% for plugin in instance.child_plugin_instances %}{% render_plugin plugin %}{% endfor %}
{% endblock %}

I would like to wrap the plugins dropped within this block with different divs. Is it possible to identify if the dropped plugin is , say, a text plugin ?

Thanks

Upvotes: 1

Views: 591

Answers (1)

Fabian
Fabian

Reputation: 850

Plugin instances have a field called plugin_type which you can use.

{% for plugin in instance.child_plugin_instances %}
    {% if plugin.plugin_type == 'TextPlugin' %}
        <div class="mytextpluginclass">{% render_plugin plugin %}</div>
    {% else %}
        {% render_plugin plugin %}
    {% endif %}
{% endfor %}

Or, you can use the field to add classes etc. to your divs.

Good luck.

Upvotes: 2

Related Questions