@@ -34,8 +34,6 @@ If you do not use the built-in components, you do not need to add them to your `
3434.. code-block :: python
3535
3636 INSTALLED_APPS = [
37- # Optional dependencies
38- ' djangocms_icon' ,
3937 ' easy_thumbnails' ,
4038 ' djangocms_link' , # Required if djangocms_frontend.contrib.link is used
4139 # Main frontend app - built-in components from contrib not needed
@@ -67,7 +65,7 @@ as required for ``djangocms-frontend`` template components.
6765Directory Structure
6866-------------------
6967
70- The templte component lives in the template directory of any of your apps.
68+ The template component lives in the template directory of any of your apps.
7169Ensure your DjangoCMS app has the following structure::
7270
7371 theme_app/
@@ -117,7 +115,10 @@ Then, add the following code::
117115 {% childplugins %}{% endchildplugins %}
118116 </div>
119117 <div class="hidden lg:mt-0 lg:col-span-5 lg:flex">
120- <img src="{{ hero_image.url }}">
118+ {# Get the related object of the image field which itself is just a dict #}
119+ {% with image=instance.hero_image|get_related_object %}
120+ <img src="{{ image.url }}" alt="{{ image.alt }}">
121+ {% endwith %}
121122 </div>
122123 </div>
123124 </section>
@@ -133,7 +134,7 @@ Component Declaration
133134 {% cms_component "Hero" name=_("My Hero Component") %}
134135
135136 This tag **declares ** the component and assigns it a name (``Hero ``). This is used internally
136- by django CMS to identify the plguin later. The ``name `` parameter is used to display the
137+ by django CMS to identify the plugin later. The ``name `` parameter is used to display the
137138component in the CMS admin interface. Internally the command declares a ``CMSFrontendComponent ``
138139class. All named arguments are added to the component's Meta class.
139140
@@ -205,27 +206,36 @@ content, i.e. add/remove ``{% field %}`` tags, or change the ``{% cms_component
205206the Django server to apply the changes.
206207
2072081. Restart your Django server.
208- 2. Create a new page end edit it.
209+ 2. Create a new page And edit it.
2092103. Add a new **Hero component ** to a page from the plugin picker.
2102114. Fill in the **title **, **slogan **, and **hero image ** fields.
2112125. Save and publish the page.
212213
213214Using the component in your templates
214215-------------------------------------
215216
216- To use the component in your templates, you can use the ``{% plugin %} `` tag with the component's name.
217- For example, to render the **Hero component ** in a template, use the following code::
217+ To use the component in your templates outside django CMS , you can use the ``{% plugin %} `` tag with the
218+ component's name. For example, to render the **Hero component ** in a template, use the following code::
218219
219220 {% load frontend %}
220221 {% plugin "hero" title=_("Welcome to my new website") slogan=_("Building successful websites since 1896") %}
221222
223+ .. note ::
224+ Do not forget to register the component with :attr: `CMS_COMPONENT_PLUGINS `. If you needed to list the single
225+ component in the setting, the hero component's dotted path to its plugin would be
226+ ``djangocms_frontend.cms_plugins.HeroPlugin ``.
227+
222228
223229Adding inline-editing to the component
224230--------------------------------------
225231
226- When using `djangocms-text <https://github.com/django-cms/djangocms-text >`_, fields of the component can be
227- marked as inline fields to activate inline editing. Simply replace ``{{ title }} `` and/or ``{{ slogan }} `` with
228- ``{% inline_field "title" %} `` and/or ``{% inline_field "slogan" %} ``::
232+ When using `djangocms-text <https://github.com/django-cms/djangocms-text >`_, `CharField ` and `HTMLFormField ` fields
233+ of the component can be marked as inline fields to activate inline editing. Inline-editing fields can be changed in
234+ the edit endpoint by simply clicking inside and typing over the text - without the need to open an edit dialogue for
235+ the component.
236+
237+ Simply replace ``{{ title }} `` and/or ``{{ slogan }} `` with ``{% inline_field "title" %} `` and/or
238+ ``{% inline_field "slogan" %} ``::
229239
230240 <h1>{% inline_field "title" %}</h1>
231241 <p>{% inline_field "slogan" %}</p>
@@ -253,12 +263,44 @@ Template components are a powerful tool for developers, but they have some limit
253263 Classes are intantiated by default, for example. This is ok for ``widget=forms.Textarea ``, but potentially not
254264 for more complex cases.
255265
266+
267+ Trouble Shooting
268+ ================
269+
270+ If the component does not appear in the plugin picker, check the following:
271+
272+ 1. **INSTALLED_APPS **: Verify that the app containing the component is listed in your ``INSTALLED_APPS `` setting.
273+
274+ 2. **Template Location **: Ensure the template file is located in the correct directory structure:
275+ ``templates/<app_name>/cms_components/ `` inside your app.
276+
277+ 3. **Server Restart **: Restart the Django server after creating or modifying the component template. Changes in
278+ the declarative part are only reflected after server restart.
279+
280+ 4. **Rendering exceptions **: The template component will only be added if it renders without exception. Make
281+ sure it does not fail if the context is empty. Check the server logs for errors during startup. Missing
282+ dependencies or syntax errors in the template can prevent the component from being registered.
283+
284+ 5. **Migration module **: Make sure the app has a migration module. If not, create one with
285+ ``python -m manage makemigrations <app_name> ``.
286+
287+ 6. **Permissions **: Add the necessary permissions for the user/group if you are not the superuser.
288+ Also see :ref: `sync_permissions `.
289+
290+ If the issue persists, double-check the template syntax and ensure all required fields are properly defined.
291+
256292Conclusion
257293==========
258294
259- You have successfully created a **djangocms-frontend template component ** using ``cms_component ``!
260- This structure allows editors to easily customize hero sections while maintaining a reusable
261- and structured design.
295+ In this tutorial, you learned how to create a reusable **Hero component ** using ``djangocms-frontend ``.
296+ This approach allows you to:
297+
298+ - Simplify component creation for editors by offering inline editing.
299+ - Maintain consistent design across your website by reusing the component.
300+ - Extend functionality without writing Python code.
301+
302+ By following these steps, you can create additional components tailored to your project's needs.
303+
262304
263305.. note ::
264306
0 commit comments