Skip to content

Commit c89999d

Browse files
committed
Update docs
1 parent 389c0ce commit c89999d

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

djangocms_frontend/templatetags/cms_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _to_tuple_if_needed(value: str) -> str | tuple[str, str]:
6464
"""
6565
match = re.match(r"^(.*?)\s*<([^>]+)>\s?$", value)
6666
if match:
67-
return [match.group(2).strip(), match.group(1).strip()]
67+
return (match.group(2).strip(), match.group(1).strip())
6868
return value
6969

7070

docs/source/tutorial/custom_components.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Building Custom Frontend Components
55
####################################
66

77
.. index::
8-
single: custom frontend components
8+
single: Custom frontend components
99

1010
.. versionadded:: 2.0
1111

docs/source/tutorial/template_components.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,33 @@ Simply replace ``{{ title }}`` and/or ``{{ slogan }}`` with ``{% inline_field "t
250250
template files, you need to restart the server manually to see the changes.
251251

252252

253+
A little helper: the ``split`` filter
254+
-------------------------------------
255+
256+
.. index::
257+
single: ``split`` filter
258+
259+
Some component properties require a list of values, such as the ``parent_classes`` or ``child_classes``.
260+
You can use the ``split`` filter to convert a string into a list. For example, if you want to allow the
261+
**Hero component** to be a child of the **Container or Column component**, you can set the ``parent_classes``
262+
like this::
263+
264+
{% cms_component "Hero" name=_("My Hero Component") parent_classes="ContainerPlugin|ColumnPlugin"|split %}
265+
266+
``split`` splits a string by the pipe character (``|``) and returns a list of strings. If you prefer to use a different
267+
separator, you can pass it as an argument to the filter, like this::
268+
269+
{% cms_component "Hero" name=_("My Hero Component") parent_classes="ContainerPlugin,ColumnPlugin"|split:"," %}
270+
271+
Additionally, ``split`` can be used to create tuples as needed for the ``choices`` parameter of
272+
``forms.ChoiceField``. For example, if you want to create a choice field with two options, you can use the
273+
following code::
274+
275+
{% field "color" forms.ChoiceField choices="Red <red>|Green <green>|Default <blue>"|split name=_("Color") %}
276+
277+
The verbose choice label is appended by the actual value of the field between angle brackets (``<...>``).
278+
279+
253280
Limitations of template components
254281
----------------------------------
255282

0 commit comments

Comments
 (0)