Skip to content

Commit 8454a28

Browse files
committed
Improve the Plugins documentation for referencability
1 parent 6bfbdfc commit 8454a28

File tree

1 file changed

+167
-85
lines changed

1 file changed

+167
-85
lines changed

docs/extending_cms/custom_plugins.rst

Lines changed: 167 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -624,17 +624,59 @@ You can nest CMS Plugins in themselves. There's a few things required to achieve
624624
Plugin Attribute Reference
625625
==========================
626626

627-
A list of all attributes a plugin has and that can be overwritten:
627+
A list of all attributes a plugin has and that can (or should) be overwritten:
628+
629+
630+
admin_preview
631+
-------------
632+
633+
Default: `False`
634+
635+
Should the plugin be previewed in admin when you click on the plugin or save it?
636+
637+
638+
639+
allow_children
640+
--------------
641+
642+
Default: `False`
643+
644+
Can this plugin have child plugins? Or can other plugins be placed inside this plugin?
645+
If set to True you are responsible to render the children in your plugin template.
646+
647+
Please use something like this or something similar::
648+
649+
{% load cms_tags %}
650+
<div class="myplugin">
651+
{{ instance.my_content }}
652+
{% for plugin in instance.child_plugin_instances %}
653+
{% render_plugin plugin %}
654+
{% endfor %}
655+
</div>
656+
657+
658+
Be sure to access ``instance.child_plugin_instances`` to get all children.
659+
They are pre-filled and ready to use. To finally render your child plugins use
660+
the ``{% render_plugin %}`` templatetag.
661+
662+
See also: `child_classes`_, `parent_classes`_, `require_parent`_
663+
664+
665+
cache
666+
-----
667+
668+
Default: :setting:`CMS_PLUGIN_CACHE`
669+
670+
Is this plugin cacheable? If your plugin displays content based on the user or
671+
request or other dynamic properties set this to False.
628672

629673

630674
change_form_template
631675
--------------------
632676

633-
The template used to render the form when you edit the plugin.
677+
Default: `admin/cms/page/plugin_change_form.html`
634678

635-
Default:
636-
637-
`admin/cms/page/plugin_change_form.html`
679+
The template used to render the form when you edit the plugin.
638680

639681
Example::
640682

@@ -644,59 +686,44 @@ Example::
644686
render_template = "cms/plugins/my_plugin.html"
645687
change_form_template = "admin/cms/page/plugin_change_form.html"
646688

647-
frontend_edit_template
648-
----------------------
689+
See also: `frontend_edit_template`_
649690

650-
The template used for wrapping the plugin in frontend editing.
651691

652-
Default:
653-
654-
`cms/toolbar/placeholder_wrapper.html`
655-
656-
657-
admin_preview
692+
child_classes
658693
-------------
659694

660-
Should the plugin be previewed in admin when you click on the plugin or save it?
661-
662-
Default: False
663-
695+
Default: `None`
664696

665-
render_template
666-
---------------
697+
A List of Plugin Class Names. If this is set, only plugins listed here can be added to this plugin.
667698

668-
The path to the template used to render the template.
669-
Is required.
699+
See also: `parent_classes`_
670700

671701

672-
render_plugin
673-
-------------
702+
disable_child_plugin
703+
--------------------
674704

675-
Should the plugin be rendered at all, or doesn't it have any output?
705+
Default: `False`
676706

677-
Default: True
707+
Disables dragging of child plugins in structure mode.
678708

679-
model
680-
-----
681709

682-
The Model of the Plugin.
683-
Required.
710+
frontend_edit_template
711+
----------------------
684712

685-
text_enabled
686-
------------
713+
Default: `cms/toolbar/placeholder_wrapper.html`
687714

688-
Default: False
689-
Can the plugin be inserted inside the text plugin?
715+
The template used for wrapping the plugin in frontend editing.
690716

691-
If this is enabled the following function need to be overwritten as well:
717+
See also: `change_form_template`_
692718

693-
**icon_src()**
694719

695-
Should return the path to an icon displayed in the text.
720+
model
721+
-----
696722

697-
**icon_alt()**
723+
This is required. The model of the Plugin. The defined model must extend
724+
:class:CMSPlugin. If your plugin does not require any per-instance settings,
725+
then this setting can be set to `CMSPlugin`.
698726

699-
Should return the alt text for the icon.
700727

701728
page_only
702729
---------
@@ -706,66 +733,87 @@ Default: False
706733
Can this plugin only be attached to a placeholder that is attached to a page?
707734
Set this to true if you always need a page for this plugin.
708735

709-
allow_children
710-
--------------
736+
See also: `child_classes`_, `parent_classes`_, `require_parent`_,
711737

712-
Default: False
713738

714-
Can this plugin have child plugins? Or can other plugins be placed inside this plugin?
715-
If set to True you are responsible to render the children in your plugin template.
716-
717-
Please use something like this or something similar::
739+
parent_classes
740+
--------------
718741

719-
{% load cms_tags %}
720-
<div class="myplugin">
721-
{{ instance.my_content }}
722-
{% for plugin in instance.child_plugin_instances %}
723-
{% render_plugin plugin %}
724-
{% endfor %}
725-
</div>
742+
Default: None
726743

744+
A list of Plugin Class Names. If this is set, this plugin may only be added
745+
to plugins listed here.
727746

728-
Be sure to access ``instance.child_plugin_instances`` to get all children. They are pre-filled
729-
and ready to use. To finally render your child plugins use the ``{% render_plugin %}`` templatetag.
747+
See also: `child_classes`_, `require_parent`_
730748

731749

732-
child_classes
750+
render_plugin
733751
-------------
734752

735-
Default: None
736-
A List of Plugin Class Names. If this is set, only plugins listed here can be added to this plugin.
753+
Default: True
737754

755+
Should the plugin be rendered at all, or doesn't it have any output? If
756+
`render_plugin` is true, then you must also define `render_template`
738757

739-
parent_classes
740-
--------------
758+
See also: `render_template`_
741759

742-
Default: None
743760

744-
A list of Plugin Class Names. If this is set, this plugin may only be added to plugins listed here.
761+
render_template
762+
_______________
763+
764+
The path to the template used to render the template. This is required if
765+
`render_plugin` is true.
766+
767+
See also: `render_plugin`_
745768

746769

747770
require_parent
748771
--------------
749772

750773
Default: False
751774

752-
Is it required that this plugin is a child of another plugin? Or can it be added to any placeholder, even one attached to a page.
775+
Is it required that this plugin is a child of another plugin? Or can it be
776+
added to any placeholder, even one attached to a page.
753777

778+
See also: `child_classes`_, `parent_classes`_
754779

755-
disable_child_plugin
756-
--------------------
780+
781+
text_enabled
782+
------------
757783

758784
Default: False
759785

760-
Disables dragging of child plugins in structure mode.
786+
Can the plugin be inserted inside the text plugin? If this is enabled then
787+
`icon_src` must be overriden.
788+
789+
See also: `icon_src`_, `icon_alt`_
790+
791+
792+
translatable_content_excluded_fields
793+
------------------------------------
794+
795+
Default: [ ]
796+
797+
A list of plugin fields which will not be exported while using
798+
:meth:`get_translatable_content`.
799+
800+
See also: `get_translatable_content`_, `set_translatable_content`_
801+
802+
803+
Plugin Method Reference
804+
=======================
805+
806+
A list of all methods a plugin has and that can (or should) be overwritten:
761807

762808

763809
get_translatable_content
764810
------------------------
765811

766-
Get a dictionary of all content fields (field name / field value pairs) from the plugin.
812+
Get a dictionary of all content fields (field name / field value pairs) from
813+
the plugin.
767814

768-
.. note:: This method and the one below should not be used on the plugin but rather on the plugin's instance.
815+
.. note:: This method not be used on the plugin but rather on the plugin's
816+
instance.
769817

770818
Example::
771819

@@ -775,11 +823,59 @@ Example::
775823
plugin.get_translatable_content()
776824
# returns {'body': u'<p>I am text!</p>\n'}
777825

826+
827+
See also: `translatable_content_excluded_fields`_, `set_translatable_content`_
828+
829+
830+
icon_src
831+
--------
832+
833+
By default, this returns an empty string, which, if left unoverridden would
834+
result in no icon rendered at all, which would render the plugin uneditable
835+
inside its parent text plugin.
836+
837+
This function accepts the `instance` parameter and should return the path to
838+
an icon to display in the text of the text plugin. Example::
839+
840+
def icon_src(self, instance):
841+
return settings.STATIC_URL + "cms/img/icons/plugins/link.png"
842+
843+
See also: `text_enabled`_, `icon_alt`_
844+
845+
846+
icon_alt
847+
--------
848+
849+
Although it is optional, authors of `text_enabled` plugins should consider
850+
overriding this function as well.
851+
852+
This function accepts the `instance` as a parameter and returns a string to be
853+
used as the alt text for the plugin's icon which will appear as a tooltip in
854+
most browsers. This is useful, because if the same plugin is used multiple
855+
times within the same text plugin, they will typically all render with the
856+
same icon rendering them visually identical to one another. This alt text and
857+
related tooltip will help the operator distinguish one from the others.
858+
859+
By default `icon_alt()` will return a string of the form: "[plugin type] -
860+
[instance]", but can be modified to return anything you like.
861+
862+
The default implementation is as follows::
863+
864+
def icon_alt(self, instance):
865+
return "%s - %s" % (force_unicode(self.name), force_unicode(instance))
866+
867+
See also: `text_enabled`_, `icon_src`_
868+
869+
778870
set_translatable_content
779871
------------------------
780872

781-
Takes a dictionary of plugin fields (field name / field value pairs) and overwrites the plugin's fields. Returns True if all fields
782-
have been written successfully, and False otherwise.
873+
Takes a dictionary of plugin fields (field name / field value pairs) and
874+
overwrites the plugin's fields. Returns True if all fields have been written
875+
successfully, and False otherwise.
876+
877+
.. note:: This method not be used on the plugin but rather on the plugin's
878+
instance.
783879

784880
Example::
785881

@@ -789,18 +885,4 @@ Example::
789885
plugin.set_translatable_content({'body': u'<p>This is a different text!</p>\n'})
790886
# returns True
791887

792-
translatable_content_excluded_fields
793-
------------------------------------
794-
795-
Default: [ ]
796-
797-
A list of plugin fields which will not be exported while using :meth:`get_translatable_content`
798-
799-
800-
cache
801-
-----
802-
803-
Default: :setting:`CMS_PLUGIN_CACHE`
804-
805-
Is this plugin cacheable? If your plugin displays content based on the user or request or other
806-
dynamic properties set this to False.
888+
See also: `translatable_content_excluded_fields`_, `get_translatable_content`_

0 commit comments

Comments
 (0)