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
1313needing in-depth knowledge of design, HTML, or nested structures. Editors can simply add content to pre-defined
1414components, 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
5549either keep components together in one theme app, or keep them with where
5650they 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.
6652Ensure 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+
7874Creating 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 ** .
169165In 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
193189the resulting plugin class with the exception of ``get_render_template() ``. Similarly, you cannot add
194190Python 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> `.
0 commit comments