Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cms/templates/cms/toolbar/render_plugin_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% load l10n %}
<div class="cms_plugin cms_plugin-{{ plugin.id|unlocalize }}">{{ inner }}</div>
28 changes: 27 additions & 1 deletion cms/templatetags/cms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,36 @@ def get_context(self, context, plugin):
)
}


register.tag(RenderPlugin)


class RenderPluginBlock(InclusionTag):
"""
Acts like the CMS's templatetag 'render_model_block' but with a plugin
instead of a model. This is used to link from a block of markup to a
plugin's changeform.

This is useful for UIs that have some plugins hidden from display in
preview mode, but the CMS author needs to expose a way to edit them
anyway. It is also useful for just making duplicate or alternate means of
triggering the change form for a plugin.
"""

name = 'render_plugin_block'
template = "cms/toolbar/render_plugin_block.html"
options = Options(
Argument('plugin'),
blocks=[('endrender_plugin_block', 'nodelist')],
)

def get_context(self, context, plugin, nodelist):
context['inner'] = nodelist.render(context)
context['plugin'] = plugin
return context

register.tag(RenderPluginBlock)


class PluginChildClasses(InclusionTag):
"""
Accepts a placeholder or a plugin and renders the allowed plugins for this.
Expand Down
55 changes: 55 additions & 0 deletions docs/reference/templatetags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,61 @@ Plugins need the ``allow_children`` attribute to set to `True` for this to be en
.. templatetag:: render_model
.. versionadded:: 3.0


render_plugin_block
===================

This templatetag acts like the templatetag 'render_model_block' but with a
plugin instead of a model as its target. This is used to link from a block of
markup to a plugin's changeform in edit/preview mode.

This is useful for user interfaces that have some plugins hidden from display
in edit/preview mode, but the CMS author needs to expose a way to edit them.
It is also useful for just making duplicate or alternate means of triggering
the change form for a plugin.

This would typically be used inside a parent-plugin’s render template. In this
example code below, there is a parent container plugin which renders a list of
child plugins inside a NAV block, then the actual plugin contents inside a
DIV.contentgroup-items block. In this example, the nav block is always shown,
but the items are only shown once the corresponding navigation element is
clicked. Adding this render_plugin_block makes it significantly more intuitive
to edit a child plugins content, by double-clicking its nav item in edit mode.

Arguments:

- ``plugin``

Example::

{% load cms_tags l10n %}

{% block section_content %}
<div class="contentgroup-container">
<nav class="contentgroup">
<div class="inner">
<ul class="contentgroup-items">{% for child in children %}
{% if child.enabled %}
<li class="item{{ forloop.counter0|unlocalize }}">
{% render_plugin_block child %}
<a href="#item{{ child.id|unlocalize }}">{{ child.title|safe }}</a>
{% endrender_plugin_block %}
</li>{% endif %}
{% endfor %}
</ul>
</div>
</nav>

<div class="contentgroup-items">{% for child in children %}
<div class="contentgroup-item item{{ child.id|unlocalize }}{% if not forloop.counter0 %} active{% endif %}">
{% render_plugin child %}
</div>{% endfor %}
</div>
</div>
{% endblock %}



render_model
============

Expand Down