Skip to content

Commit 12b5e6d

Browse files
authored
docs: Add inline-editing how-to (#261)
1 parent cc51127 commit 12b5e6d

File tree

3 files changed

+121
-3
lines changed

3 files changed

+121
-3
lines changed

docs/source/how-to/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ step-by-step guidance.
1313
:maxdepth: 1
1414

1515
use-frontend-as-component
16+
inline-editing
1617
add-frontend-plugins
1718
extend-frontend-plugins
1819
add-tab-style

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

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.. _inline_editing_custom_components:
2+
3+
################################################
4+
How to Use Inline Editing with Custom Components
5+
################################################
6+
7+
.. versionadded:: 2.0
8+
9+
``djangocms-frontend`` introduces simplified support for **inline editing** in custom
10+
components, making it easier to edit content directly on the page without opening the
11+
plugin'S change form. This guide will walk you through using the ``inline_field``
12+
template tag to enable inline editing for your custom frontend components.
13+
14+
.. note::
15+
16+
Inline editing requires djangocms-text to be installed and configured in your project.
17+
18+
19+
Understanding the ``inline_field`` Template Tag
20+
=============================================
21+
22+
The ``inline_field`` template tag allows you to make specific fields editable directly from
23+
the page. It works by wrapping a field in an inline editing context, which is recognized by
24+
django CMS's edit mode.
25+
26+
Syntax:
27+
28+
.. code-block:: django
29+
30+
{% load frontend_tags %}
31+
{% inline_field instance "field_name" %}
32+
33+
- ``instance`` - The plugin or model instance.
34+
- ``"field_name"`` - The name of the field you want to make editable inline.
35+
36+
If not in edit mode the template tag will render the field as plain text.
37+
38+
.. note::
39+
40+
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+
46+
47+
Step-by-Step: Adding Inline Editing to a Custom Component
48+
=========================================================
49+
50+
1. **Define Your Custom Component Plugin**
51+
52+
First, create a djangoCMS plugin for your custom component. Example:
53+
54+
.. code-block:: python
55+
56+
from cms.plugin_base import CMSPluginBase
57+
from cms.plugin_pool import plugin_pool
58+
from django.utils.translation import gettext_lazy as _
59+
from djangocms_frontend.models import FrontendUIItem
60+
61+
class CustomComponentPlugin(CMSPluginBase):
62+
model = FrontendUIItem # Base model
63+
name = _("Custom Component")
64+
module = _("Frontend")
65+
render_template = "frontend/custom_component.html"
66+
67+
plugin_pool.register_plugin(CustomComponentPlugin)
68+
69+
2. **Modify the Component Template to Support Inline Editing**
70+
71+
Open the template file (``frontend/custom_component.html``) and update it using the
72+
``inline_field`` tag:
73+
74+
.. code-block:: django
75+
76+
{% load frontend_tags %}
77+
78+
<div class="custom-component">
79+
<h2>{% inline_field instance "title" %}</h2>
80+
<p>{% inline_field instance "description" %}</p>
81+
</div>
82+
83+
3. **Explicitly allow the field for inline editing**
84+
85+
In the plugin definition, add the field to the ``frontend_editable_fields`` list:
86+
87+
.. code-block:: python
88+
89+
class CustomComponentPlugin(CMSPluginBase):
90+
model = FrontendUIItem # Base model
91+
name = _("Custom Component")
92+
module = _("Frontend")
93+
render_template = "frontend/custom_component.html"
94+
frontend_editable_fields = ["title", "description"]
95+
96+
4. **Test Inline Editing**
97+
98+
- Run the Django server:
99+
100+
.. code-block:: bash
101+
102+
python manage.py runserver
103+
104+
- Log in as an admin user and enter **Edit Mode**.
105+
- Add your custom component to a page.
106+
- Click on the text fields to edit them inline.
107+
- Leave the field, and changes will be stored automatically in the database.
108+
109+
110+
Additional Considerations
111+
=========================
112+
113+
- **Rich Text Editing:** If the field is a ``HTMLField``, django CMS text will automatically use
114+
a rich text editor for inline editing.
115+
- **CSS & JavaScript Adjustments:** In rare cases custom component's styles can interfere
116+
with django CMS text's inline editing interface. More specific rules typically solve the issue.

docs/source/how-to/use-frontend-as-component.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
.. _components:
33

4-
Using frontend plugins as components in templates
5-
=================================================
4+
How to use frontend plugins as components in templates
5+
======================================================
66

77
.. versionadded:: 2.0
88

@@ -99,8 +99,9 @@ use the ``{% plugin %}`` template tag with each plugin.
9999
a ``{% plugin %}`` tag. This is because the ``{% plugin %}`` tag does
100100
preprocess the content and placeholders are not recognized by django CMS.
101101

102+
102103
Multi-line tags
103-
===============
104+
---------------
104105

105106
Multi-line tags are not supported in Django templates. For components with many
106107
parameters this can lead to long lines of code. To make the code more readable

0 commit comments

Comments
 (0)