Skip to content

Commit 6003b17

Browse files
authored
docs: update (#239)
1 parent a50d679 commit 6003b17

File tree

9 files changed

+81
-21
lines changed

9 files changed

+81
-21
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ For a manual install:
115115

116116
- run ``pip install djangocms-frontend``
117117

118-
- add the following entries to your ``INSTALLED_APPS``:
118+
- add the following entries to your ``INSTALLED_APPS`` (or only those you need):
119119

120120
.. code::
121121
@@ -127,6 +127,7 @@ For a manual install:
127127
'djangocms_frontend.contrib.card',
128128
'djangocms_frontend.contrib.carousel',
129129
'djangocms_frontend.contrib.collapse',
130+
'djangocms_frontend.contrib.component',
130131
'djangocms_frontend.contrib.content',
131132
'djangocms_frontend.contrib.grid',
132133
'djangocms_frontend.contrib.icon',

djangocms_frontend/contrib/collapse/templates/djangocms_frontend/bootstrap5/collapse-container.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<{{ instance.tag_type }}{{ instance.get_attributes }}
33
id="{{ instance.container_identifier }}"
44
role="tabpanel"
5-
data-bs-parent="#parent-{{ parent.pk|safe }}"
5+
data-bs-parent="#{{ parent.uuid }}"
66
aria-labelledby="trigger-{{ instance.container_identifier }}">
77
{% for plugin in instance.child_plugin_instances %}
88
{% with forloop as parentloop %}{% render_plugin plugin %}{% endwith %}

djangocms_frontend/contrib/collapse/templates/djangocms_frontend/bootstrap5/collapse.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% load cms_tags frontend %}
22
<{{ instance.tag_type }}{{ instance.get_attributes }}
3-
id="parent-{{ instance.pk|safe }}"
3+
id="{{ instance.uuid }}"
44
data-bs-children="{{ instance.collapse_siblings }}"
55
role="tablist"
66
>

djangocms_frontend/contrib/content/cms_plugins.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class BlockquotePlugin(
7777
),
7878
]
7979

80+
frontend_editable_fields = ("quote_content", "quote_origin")
81+
8082

8183
@plugin_pool.register_plugin
8284
class FigurePlugin(
@@ -110,3 +112,5 @@ class FigurePlugin(
110112
},
111113
),
112114
]
115+
116+
frontend_editable_fields = ("figure_caption",)

djangocms_frontend/contrib/content/templates/djangocms_frontend/bootstrap5/blockquote.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
{# djlint:on #}
1010
{% for plugin in instance.child_plugin_instances %}
1111
{% with parentloop=forloop parent=instance %}{% render_plugin plugin %}{% endwith %}
12-
{% empty %}{{ instance.quote_content|html_safe }}{% endfor %}
12+
{% empty %}{% inline_field instance "quote_content" "" "html_safe" %}{% endfor %}
1313
{# djlint:off #}
1414
</blockquote>
1515
{# djlint:on #}
1616
{% if instance.quote_origin %}
1717
<figcaption class="blockquote-footer">
18-
{{ instance.quote_origin|safe_caption }}
18+
{% inline_field instance "quote_origin" "" "safe_caption" %}
1919
</figcaption>
2020
</figure>
2121
{% endif %}

djangocms_frontend/contrib/content/templates/djangocms_frontend/bootstrap5/figure.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
{% for plugin in instance.child_plugin_instances %}
44
{% with forloop=parentloop parent=instance %}{% render_plugin plugin %}{% endwith %}
55
{% endfor %}
6-
<figcaption class="figure-caption{% if figure_alignment %} text-{{ figure_alignment }}{% endif %}">{{ instance.figure_caption|safe_caption }}</figcaption>
6+
<figcaption class="figure-caption{% if figure_alignment %} text-{{ figure_alignment }}{% endif %}">{% inline_field instance "figure_caption" "" "safe_caption" %}</figcaption>
77
</figure>

docs/source/custom_components.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Custom Components
55
#################
66

7+
.. versionadded:: 2.0
8+
79
Some frontend developers prefer custom components specifically tailored to
810
give the project a unique and distinct look.
911

docs/source/getting_started.rst

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Add the following entries to your ``INSTALLED_APPS``:
5151
"djangocms_frontend.contrib.card",
5252
"djangocms_frontend.contrib.carousel",
5353
"djangocms_frontend.contrib.collapse",
54+
"djangocms_frontend.contrib.component",
5455
"djangocms_frontend.contrib.content",
5556
"djangocms_frontend.contrib.grid",
5657
"djangocms_frontend.contrib.icon",
@@ -62,12 +63,6 @@ Add the following entries to your ``INSTALLED_APPS``:
6263
"djangocms_frontend.contrib.tabs",
6364
"djangocms_frontend.contrib.utilities",
6465
65-
.. note :: Using Django 2.2 to 3.1
66-
67-
You will need to add ``django-jsonfield-backport`` to your
68-
``requirements.txt`` and add ``"django_jsonfield_backport"`` to your
69-
``INSTALLED_APPS``.
70-
7166
7267
Create necessary database table
7368
===============================
@@ -440,15 +435,19 @@ the upper right corner:
440435
Using frontend plugins as components in templates
441436
=================================================
442437

438+
.. versionadded:: 2.0
439+
443440
The plugins of **djangocms-frontend** can be used as components in your
444441
templates - even in apps that do not use or integrate with djanog CMS
445442
otherwise. This is useful if you want use exactly the same markup for, say,
446443
buttons, links, the grid both in pages managed with django CMS and in
447-
other parts of your project.
444+
other parts of your project without duplicating HTML code.
448445

449-
This allows you to keep one set of templates for your django CMS frontend
450-
plugins and any changes to those templates will be reflected in all parts
451-
of your project.
446+
This feature introduces a simple and flexible way to re-use djangocms-frontend
447+
plugins directly in templates without needing to create database entries for
448+
them. This allows developers to maintain clean, reusable, and dynamic
449+
components, such as buttons, cards, links, and more, while minimizing code
450+
repetition.
452451

453452
To use a frontend plugin in a template you need to load the ``frontend`` tags
454453
and then use the ``plugin`` template tag to render a frontend plugin.
@@ -464,15 +463,48 @@ The plugins will be rendered based on their standard attribute settings.
464463
You can override these settings by passing them as keyword arguments to the
465464
``plugin`` template tag.
466465

467-
See the documentation of the djanog CMS plugins for examples of how to use
468-
the ``{% plugin %}`` template tag with each plugin.
466+
You can also create more complex reusable components, like a card with inner
467+
elements such as headers, bodies, and lists, by nesting plugins. Here’s an
468+
example of a card component::
469+
470+
{% load frontend %}
471+
{% plugin "card" card_alignment="center" card_outline="info" card_text_color="primary" card_full_height=True %}
472+
{% plugin "cardinner" inner_type="card-header" text_alignment="start" %}
473+
<h4>Card title</h4>
474+
{% endplugin %}
475+
{% plugin "cardinner" inner_type="card-body" text_alignment="center" %}
476+
Some quick example text to build on the card title and make up the bulk of the card's content.
477+
{% endplugin %}
478+
{% plugin "listgroupitem" %}An item{% endplugin %}
479+
{% plugin "listgroupitem" %}A second item{% endplugin %}
480+
{% plugin "listgroupitem" %}A third item{% endplugin %}
481+
{% endplugin %}
482+
483+
Breakdown of the Code:
484+
485+
* ``plugin "card"``: Creates the outer card component.
486+
* ``card_alignment="center"``: Aligns the card content to the center.
487+
* ``card_outline="info"``: Gives the card an "info" outline style.
488+
* ``card_text_color="primary"``: Changes the text color to "primary."
489+
* ``card_full_height=True``: Ensures the card takes up the full height of its container.
490+
* Nested ``plugin "cardinner"``: Creates inner components within the card.
491+
* ``inner_type="card-header"``: Specifies a header section for the card.
492+
* ``text_alignment="start"``: Aligns the header text to the start (left).
493+
* Additional nested ``plugin "cardinner"`` and ``listgroupitem``:
494+
* These create the body of the card and a list group inside the card.
495+
496+
The above template generates a dynamic card component with a header, a body,
497+
and a list group that can be reused across multiple pages without requiring
498+
database entries.
499+
500+
For more examples, see the documentation of the djanog CMS plugins on of how to
501+
use the ``{% plugin %}`` template tag with each plugin.
502+
469503

470504
.. note::
471505

472506
While this is designed for **djangocms-frontend** plugins primarily, it
473-
will work with most django CMS plugins.
507+
will work with many other django CMS plugins.
474508

475509
Since no plugins are created in the database, plugins relying on their
476510
instances being available in the database will potentially not work.
477-
This especially is true for plugins that have a foreign key to
478-
other models.

docs/source/grid.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ Full container
3737
New feature:
3838
Containers can have a background color ("context"), opacity and shadow.
3939

40+
Component example
41+
=================
42+
43+
To create a container in a Django template, you need to load the `frontend` tags
44+
and then use the `plugin` template tag to render the container plugin.
45+
Below is an example of how you might do this::
46+
47+
{% load frontend %}
48+
49+
<!-- Example of using the plugin template tag for a container -->
50+
{% plugin "container" container_type="container-fluid" %}
51+
{% plugin "row" %}
52+
{% plugin "column" xs_col=6 %}
53+
<p>This is the first column inside the container.</p>
54+
{% endplugin %}
55+
{% plugin "column" xs_col=6 %}
56+
<p>This is the second column inside the container.</p>
57+
{% endplugin %}
58+
{% endplugin %}
59+
{% endplugin %}
60+
4061

4162
.. index::
4263
single: Row

0 commit comments

Comments
 (0)