Skip to content

Commit c0f7c0b

Browse files
committed
Cleanup of tutorials, needs fixing some markup errors
1 parent ce49f00 commit c0f7c0b

File tree

4 files changed

+80
-123
lines changed

4 files changed

+80
-123
lines changed

docs/source/tutorial/builtin_components.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _built_in_components:
22

33
######################################
4-
Using Built-In Bootstrap 5 Components
4+
Installation and Usage with Built-In Components
55
######################################
66

77
.. index::
@@ -91,6 +91,21 @@ Configuration
9191
'djangocms_frontend.contrib.utilities',
9292
]
9393
94+
For example, if you don't want to use any built-in components because you plan on
95+
:ref:`building your own <custom_components>`, a minimal setup of ``INSTALLED_APPS``
96+
would look like this:
97+
98+
.. code-block:: python
99+
100+
INSTALLED_APPS = [
101+
'easy_thumbnails',
102+
'djangocms_link', # Required if djangocms_frontend.contrib.link is used
103+
# Main frontend app - pre-built components not needed
104+
'djangocms_frontend',
105+
]
106+
107+
108+
94109
2. **Apply Migrations**
95110

96111
Run the following command to create the necessary database tables:

docs/source/tutorial/custom_components.rst

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,57 @@
11
.. _custom_components:
22

3-
####################################
4-
Building Custom Frontend Components
5-
####################################
3+
#######################################
4+
Building Custom CMS Frontend Components
5+
#######################################
66

77
.. index::
88
single: Custom frontend components
99

1010
.. versionadded:: 2.0
1111

12-
Custom frontend components are a powerful tool for content editors, allowing them to build pages without
12+
**Custom CMS Frontend components** are a powerful tool for content editors, allowing them to build pages without
1313
needing in-depth knowledge of design, HTML, or nested structures. Editors can simply add content to pre-defined
1414
components, creating visually cohesive pages with ease.
1515

16-
When working with `Tailwind CSS <https://tailwindcss.com>`_, for example, you either create your custom
17-
frontend components or customize components from providers, e.g. `Tailwind UI <https://tailwindui.com>`_,
18-
`Flowbite <https://flowbite.com>`_, or the community `Tailwind Components <https://tailwindcomponents.com>`_.
16+
`djangocms-frontend` provides a simple way for developers to create **custom Frontend CMS Components**,
17+
by subclassing the `CMSFrontendComponent` class and providing a custom template.
18+
This approach requires minimal
19+
Python coding, while still offering flexibility and control over the component's behavior and appearance.
1920

20-
With django CMS you make your components available to the content editors to simply add them to a page by a
21-
click **and** frontend developers for use in templates from a single source.
2221

23-
Custom frontend components are more versatile than template components, but require some minimal Python coding.
24-
Technically, you create a custom frontend component by declaring its change form and rendering template.
2522

26-
Installation
27-
============
2823

29-
Install ``djangocms-frontend`` and add it to your project as described here: :ref:`built_in_components`.
24+
In this tutorial, we will explore how to create custom **CMS Frontend Components**.
25+
These components empower developers to provide visually appealing components to content editors
26+
with minimal coding.
3027

31-
If you do not use the built-in components, you do not need to add them to your ``INSTALLED_APPS``.
28+
- Components are defined by subclassing the `CMSFrontendComponent` class.
29+
- Visual presentation is controlled via templates.
30+
- Django CMS allows to register and manage these components seamlessly.
3231

33-
.. code-block:: python
32+
Custom frontend components are more versatile than :ref:`template_components`, but require some minimal
33+
Python coding. Technically, you create a custom frontend component by declaring its change form and
34+
rendering template.
3435

35-
INSTALLED_APPS = [
36-
'easy_thumbnails',
37-
'djangocms_link', # Required if djangocms_frontend.contrib.link is used
38-
# Main frontend app - pre-built components not needed
39-
'djangocms_frontend',
40-
]
4136

37+
Hero CMS component example
38+
==========================
4239

43-
Adding Styles and JavaScript
44-
============================
40+
In this tutorial we will create again a **Hero component** similar to the one in the
41+
:ref:`previous chapter <template_components>`, but this time with python code.
4542

46-
When building template components, you will need to provide your custom CSS files
47-
either by adding them to the base templates to load on every page, or by adding a
48-
django-sekizai block to each component.
4943

50-
Hero component example
51-
======================
44+
Directory Structure
45+
-------------------
5246

5347
``djangocms-frontend`` will look for custom frontend components in the
54-
**``cms_components`` module in any of your apps**. This way you can
48+
**``cms_components`` module in any of your installed apps**. This way you can
5549
either keep components together in one theme app, or keep them with where
5650
they are used in different custom apps.
5751

58-
Directory Structure
59-
-------------------
60-
61-
Let's go through this by creating a theme app::
62-
63-
python manage.py startapp theme
64-
65-
Custom frontend components live in the ``cms_components`` module of any of your apps.
6652
Ensure your app has the following structure::
6753

68-
theme/
54+
theme_app/
6955
cms_components.py
7056
migrations/
7157
models.py
@@ -75,6 +61,16 @@ Ensure your app has the following structure::
7561
views.py
7662
admin.py
7763

64+
In this example, `cms_components.py` will contain the component definition, and `hero.html`
65+
the presentation template.
66+
67+
.. note::
68+
69+
Components will create migrations since they use proxy models of ``djangocms-frontend``'s
70+
``FrontendUIItem`` model which are necessary, for example, to manage permissions.
71+
Those migrations will be added to the app containing the ``cms_component.py`` file.
72+
73+
7874
Creating two Custom Frontend Components
7975
---------------------------------------
8076

@@ -165,7 +161,7 @@ The templates could be, for example:
165161
<a class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800"
166162
href="{{ instance.link|to_url }}">{{ instance.text }}</a>
167163
168-
As always, django CMS manages styling and JavaScript dependencies with django-sekizai.
164+
As always, django CMS manages styling and JavaScript dependencies with **django-sekizai**.
169165
In this example, we add the Tailwind CSS CDN to the ``js`` block.
170166

171167

@@ -193,22 +189,4 @@ and can contain Python code to modify the behavior of a form. You cannot directl
193189
the resulting plugin class with the exception of ``get_render_template()``. Similarly, you cannot add
194190
Python code the model class, in this case with the exception of ``get_short_description()``.
195191

196-
197-
Conclusion
198-
==========
199-
200-
In this tutorial, we explored how to create custom frontend components. These components empower developers to
201-
provide visually appealing components to content editors with minimal coding.
202-
203-
By following the steps outlined above, you can:
204-
205-
- Create a theme app to house your custom components.
206-
- Define components using the `CMSFrontendComponent` class.
207-
- Leverage templates to control the visual presentation of your components.
208-
- Register and manage your components seamlessly within django CMS.
209-
210-
.. note::
211-
212-
Components will create migrations since they use proxy models of ``djangocms-frontend``'s
213-
``FrontendUIItem`` model which are necessary, for example, to manage permissions.
214-
Those migrations will be added to the app containing the ``cms_component.py`` file.
192+
For maximun flexibility in your customized components, you can build a :ref:`custom Plugin<how-to-add-frontend-plugins>`.

docs/source/tutorial/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ that gets the job done for your project.
1818
added to your project's ``INSTALLED_APPS``.
1919

2020
2. **Template Components** – The easiest approach creating or porting your own
21-
**custom frontend components**, allowing you define components by their HTML templates. Special
21+
custom components, allowing you **define them by their HTML templates, without any code**. Special
2222
``djangocms-frontend`` tags are used to provide the additional declarative information
2323
needed. This is the fastest approach to create ``djangocms-frontend`` components.
2424
Template-based (or auto) components are auto-detected.
2525

26-
3. **Custom Frontend Component** development – A more advanced method that lets you create
26+
3. **Custom CMS Frontend Component** development – A more advanced method that lets you create
2727
custom components with **minimal code**. This approach is more flexible than the
2828
template-based method, but requires some Python coding providing more control over
2929
the components add and change forms, for example.

docs/source/tutorial/template_components.rst

Lines changed: 25 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,29 @@ Building Template Components
1010

1111
.. versionadded:: 2.1
1212

13-
Custom components are a powerful tool for content editors, allowing them to build pages without needing
14-
in-depth knowledge of design, HTML, or nested structures. Editors can simply add content to pre-defined
15-
components, creating visually cohesive pages with ease.
13+
**Template components** are the easiest approach to creating or porting your own custom
14+
frontend components, allowing you to define custom components **using django templates,
15+
without needing to write any Python code**.
1616

17-
When working with `Tailwind CSS <https://tailwindcss.com>`_, for example, you
18-
either create your custom components or customize components from providers,
19-
e.g. `Tailwind UI <https://tailwindui.com>`_,
20-
`Flowbite <https://flowbite.com>`_, or the community
21-
`Tailwind Components <https://tailwindcomponents.com>`_.
2217

23-
With django CMS you make your components available to the content editors to
24-
simply add them to a page by a click **and** frontend developers for use in templates from a single
25-
source.
18+
Example Hero Template Component
19+
===============================
2620

27-
Installation
28-
============
29-
30-
Install ``djangocms-frontend`` and add it to your project as described here: :ref:`built_in_components`.
31-
32-
If you do not use the built-in components, you do not need to add them to your ``INSTALLED_APPS``.
33-
34-
.. code-block:: python
35-
36-
INSTALLED_APPS = [
37-
'easy_thumbnails',
38-
'djangocms_link', # Required if djangocms_frontend.contrib.link is used
39-
# Main frontend app - built-in components from contrib not needed
40-
'djangocms_frontend',
41-
]
42-
43-
44-
Adding Styles and JavaScript
45-
============================
46-
47-
When building template components, you will need to provide your custom CSS files
48-
either by adding them to the base templates to load on every page, or by adding a
49-
django-sekizai block to each component.
50-
51-
Hero component
52-
==============
53-
54-
``djangocms-frontend`` allows developers to extend its functionality by creating
55-
**template components**. In this tutorial, we will create an **Hero component**
56-
with the following fields:
21+
In this tutorial, we will create a **Hero template component** with the following fields:
5722

5823
- ``title``: A required text field.
5924
- ``slogan``: A required text area field.
6025
- ``hero_image``: A required image field.
6126

62-
This component will be stored in a template directory named ``<app_name>/cms_components``
63-
(or any subdirectory thereof).
64-
65-
.. note::
66-
You can change the location of your template components inside your template directory
67-
by setting the :attr:`DJANGOCMS_FRONTEND_COMPONENT_FOLDER` setting. The default is
68-
``cms_components``. If you change it, you need to adjust the directory structure accordingly.
69-
27+
This component will be declared by using special djangocms tags in a template file,
28+
with no python code required.
7029

7130
Directory Structure
7231
-------------------
7332

74-
The template component lives in the template directory of any of your apps.
33+
`djangocms-frontend` will **automatically locate and register template components** by looking for them
34+
**in the `templates/<app_name>/cms_components/` directory** of your installed apps.
35+
7536
Ensure your DjangoCMS app has the following structure::
7637

7738
theme_app/
@@ -84,20 +45,19 @@ Ensure your DjangoCMS app has the following structure::
8445
views.py
8546
admin.py
8647

87-
Creating the Template Component
88-
--------------------------------
48+
In this case, `heme_app/templates/theme_app/cms_components/hero.html` will be the template
49+
defining our custom hero component.
8950

90-
The **template component** must be stored in the ``cms_components`` directory
91-
inside your app. ``djangocms-frontend`` expects you to follow Django's template
92-
namespace convention. Create a new file at::
51+
.. note::
52+
You can change the location of your template components inside your template directory
53+
by setting the :attr:`DJANGOCMS_FRONTEND_COMPONENT_FOLDER` setting. The default is
54+
``cms_components``. If you change it, you need to adjust the directory structure accordingly.
9355

94-
theme_app/templates/theme_app/cms_components/hero.html
9556

96-
.. note::
97-
No python code is required to create the component. The component is
98-
defined in the template itself.
57+
Creating the Template Component
58+
--------------------------------
9959

100-
Then, add the following code::
60+
Add the following code to the `hero.html` template::
10161

10262
<!-- theme_app/templates/theme_app/cms_components/hero.html -->
10363
{% load frontend cms_component %}
@@ -291,7 +251,7 @@ The verbose choice label is appended by the actual value of the field between an
291251

292252

293253
Limitations of template components
294-
----------------------------------
254+
==================================
295255

296256
Template components are a powerful tool for developers, but they have some limitations:
297257

@@ -305,6 +265,10 @@ Template components are a powerful tool for developers, but they have some limit
305265
Classes are instantiated by default, for example. This is ok for ``widget=forms.Textarea``, but potentially not
306266
for more complex cases.
307267

268+
For more powerful customization options, consider building a :ref:`custom CMS Frontend Component <custom_components>`
269+
or a :ref:`custom Plugin<how-to-add-frontend-plugins>`
270+
271+
308272
Examples
309273
========
310274

0 commit comments

Comments
 (0)