Container¶
Models¶
A container component with a title, image, features, content and able to include children plugins.
- class cmsplugin_blocks.models.container.Container(*args, **kwargs)[source]¶
Container component.
- title¶
An optional title string.
- template¶
Template choice from available plugin templates in setting
BLOCKS_CONTAINER_TEMPLATES. Default to the first choice item.
- image¶
Optional image file.
- image_alt¶
An optional text string for alternative image text.
- size_features¶
Optional related size features.
- color_features¶
Optional related color features.
- extra_features¶
Optional related extra features.
- content¶
Required long text, it will be editable through CKeditor on plugin form.
Factories¶
Forms¶
- class cmsplugin_blocks.forms.container.ContainerForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]¶
Container form used in plugin editor.
- property media¶
Return all media required to render the widgets on this form.
Plugins¶
- class cmsplugin_blocks.plugins.container.ContainerPlugin(model=None, admin_site=None)[source]¶
- module = 'Blocks'¶
Modules collect plugins of similar type
- name = 'Container'¶
Name of the plugin needs to be set in child classes
- form¶
alias of
ContainerForm
- allow_children = True¶
Allows this plugin to have child plugins - other plugins placed inside it?
If
Trueyou need to ensure that your plugin can render its children in the plugin template. For example:{% load cms_tags %} <div class="myplugin"> {{ instance.my_content }} {% for plugin in instance.child_plugin_instances %} {% render_plugin plugin %} {% endfor %} </div>
instance.child_plugin_instancesprovides access to all the plugin’s children. They are pre-filled and ready to use. The child plugins should be rendered using the{% render_plugin %}template tag.See also:
child_classes,parent_classes,require_parent.
- render_template = 'cmsplugin_blocks/container/default.html'¶
The path to the template used to render the template. If
render_pluginisTrueeither this orget_render_templatemust be defined. See also:render_plugin,get_render_template().
- cache = True¶
Is this plugin cacheable? If your plugin displays content based on the user or request or other dynamic properties set this to
False.If present and set to
False, the plugin will prevent the caching of the resulting page.Important
Setting this to
Falsewill effectively disable the CMS page cache and all upstream caches for pages where the plugin appears. This may be useful in certain cases but for general cache management, consider using the much more capableget_cache_expiration().Warning
If you disable a plugin cache be sure to restart the server and clear the cache afterwards.
- get_fieldsets(request, obj=None)[source]¶
Define plugin form fieldsets depending features are enabled or not (when there is no defined feature choices).
- render(context, instance, placeholder)[source]¶
This method returns the context to be used to render the template specified in
render_template.- Parameters:
context (dict) – The context with which the page is rendered.
instance (
cms.models.pluginmodel.CMSPlugininstance) – The instance of your plugin that is rendered.placeholder (str) – The name of the placeholder that is rendered.
- Return type:
dict or
django.template.Context
This method must return a dictionary or an instance of
django.template.Context, which will be used as context to render the plugin template.By default, this method will add
instanceandplaceholderto the context, which means for simple plugins, there is no need to overwrite this method.If you overwrite this method it’s recommended to always populate the context with default values by calling the render method of the super class:
def render(self, context, instance, placeholder): context = super().render(context, instance, placeholder) ... return context