Skip to content

Commit 3419e17

Browse files
committed
update docs
1 parent aa1d1cd commit 3419e17

File tree

3 files changed

+69
-10
lines changed

3 files changed

+69
-10
lines changed

docs/source/how-to/inline-editing.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,26 @@ Syntax:
3333
- ``instance`` - The plugin or model instance.
3434
- ``"field_name"`` - The name of the field you want to make editable inline.
3535

36-
If not in edit mode the template tag will render the field as plain text.
36+
If the instance is called ``"instance"`` in the context, the tag can be abbreviated by
37+
``{% inline_field "field_name" %}``.
38+
39+
When the page is in edit mode, the template tag will render the field as an editable text
40+
input. If not in edit mode the template tag will render the field as plain text.
3741

3842
.. note::
3943

4044
The ``inline_field`` tag is only available for fields that are explicitly listed in
41-
the ``frontend_editable_fields`` property of the plugin. The tag itself is a shortcut
42-
for django CMS's ``render_model`` tag. Since django CMS 5, this tags works for all
43-
CMS plugins (and not only for third-party models). For earlier versions of django CMS
44-
``djangocms-frontend`` includes a custom extension for frontend plugins to support inline editing.
45+
the ``frontend_editable_fields`` property of the plugin. When run in a template component,
46+
the tag will automatically register the field with the list of editable fields.
47+
48+
The tag itself is a shortcut for django CMS's ``render_model`` tag. Since django CMS 5, this
49+
tags works for all CMS plugins (and not only for third-party models). For earlier versions
50+
of django CMS ``djangocms-frontend`` includes a custom extension for frontend plugins to
51+
support inline editing.
4552

4653

4754
Step-by-Step: Adding Inline Editing to a custom frontend component
48-
=========================================================
55+
==================================================================
4956

5057
1. **Define Your Custom Component Plugin**
5158

docs/source/reference.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ in your project's ``settings.py``.
2727
# add other plugins here if needed
2828
]
2929

30+
31+
.. py:attribute:: settings.DJANGOCMS_FRONTEND_COMPONENT_FIELDS
32+
33+
Defaults to ``{}``
34+
35+
A dictionary of installed Django apps and a list of Django form fields to be provided
36+
to :ref:`template components <template_components>`' context during their registration.
37+
The form fields can be used with the ``{% field %}`` template tag.
38+
39+
For example, to add a custom field to the context of all components, add the following line to your project's settings::
40+
41+
DJANGOCMS_FRONTEND_COMPONENT_FIELDS = {
42+
"myapp": [
43+
"myapp.fields.MySuperFieldField",
44+
"myapp.fields.ChatBotField",
45+
],
46+
# add other apps here if needed
47+
}
48+
49+
These fields can be used in the template like this::
50+
51+
{% field "superField" MySuperFieldField required=True %}
52+
{% field "chat_bot" ChatBotField required=False %}
53+
54+
Fields are only imported into the context if the app is installed in the project's ``INSTALLED_APPS``.
55+
3056
.. py:attribute:: settings.DJANGOCMS_FRONTEND_TAG_CHOICES
3157
3258
Defaults to ``['div', 'section', 'article', 'header', 'footer', 'aside']``.

docs/source/tutorial/template_components.rst

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Understanding the Code
128128
Component Declaration
129129
^^^^^^^^^^^^^^^^^^^^^
130130

131-
::
131+
.. code-block:: django
132132
133133
{% cms_component "Hero" name=_("My Hero Component") %}
134134
@@ -139,10 +139,36 @@ class. All named arguments are added to the component's Meta class.
139139

140140
Only one ``{% cms_component %}`` tag is allowed per template file.
141141

142+
The first part is the declarative part of the template:
143+
144+
.. code-block: django
145+
{% cms_component "Hero" name=_("My Hero Component") %}
146+
{% field "title" forms.CharField required=True name=_("Title") %}
147+
{% field "slogan" forms.CharField required=True name=_("Slogan") widget=forms.Textarea %}
148+
{% field "hero_image" ImageFormField required=True name=_("Image") help_text=_("At least 1024px wide image") %}
149+
150+
It will render empty. During project startup, however, these tags are evaluated and used to create the ``CMSFrontendComponent`` class
151+
and the corresponding plugins class.
152+
153+
The named parameters are added to the ``CMSFrontendComponent``'s Meta class and end up as properties of the plugin itself. The
154+
following attributes are allowed:
155+
156+
* ``name``: The name of the component as it will be displayed in the CMS admin interface.
157+
* ``module``: The module the component belongs to. This is used to group components in the CMS admin interface.
158+
* ``disable_edit``: If set to ``True``, the component will not be editable in the frontend.
159+
* ``show_add_form``: If set to ``False``, the component will not show an add form in the frontend. This is useful if
160+
all component fields have valid initial values.
161+
* ``require_parent``: If set to ``True``, the component will only be available if it is a child of another component.
162+
* ``parent_classes``: A list of plugin classes that can be parents of this component.
163+
* ``child_classes``: A list of plugin classes that can be children of this component.
164+
165+
``allow_children`` and ``frontend_editable_fields`` are set automatically.
166+
167+
142168
Defining Fields
143169
^^^^^^^^^^^^^^^
144170

145-
::
171+
.. code-block:: django
146172
147173
{% field "title" forms.CharField required=True name=_("Title") %}
148174
{% field "slogan" forms.CharField required=True name=_("Slogan") widget=forms.Textarea %}
@@ -154,7 +180,7 @@ form field class to use. The remaining parameters are passed to the form field c
154180

155181
By default, Django's ``django.forms`` module is available as ``forms`` in the template context. If the relevant apps are
156182
installed, additional fields available are ``HTMLFormField`` for rich text, ``LinkFormField`` for links, and ``ImageFormField``
157-
for images. Custom fields can be added to the context using the :ref:`CMS_FRONTEND_CUSTOM_FIELDS` setting.
183+
for images. Custom fields can be added to the context using the :attr:`~settings.DJANGOCMS_FRONTEND_COMPONENT_FIELDS` setting.
158184

159185
You can add additional fields to the component by adding more ``{% field %}`` tags.
160186

@@ -198,7 +224,7 @@ Adding inline-editing to the component
198224
--------------------------------------
199225

200226
When using `djangocms-text <https://github.com/django-cms/djangocms-text>`_, fields of the component can be
201-
marked as inline fields to activate inline editing. Simply replace ``{{ title }}``and/or ``{{ slogan }}`` with
227+
marked as inline fields to activate inline editing. Simply replace ``{{ title }}`` and/or ``{{ slogan }}`` with
202228
``{% inline_field "title" %}`` and/or ``{% inline_field "slogan" %}``::
203229

204230
<h1>{% inline_field "title" %}</h1>

0 commit comments

Comments
 (0)