Skip to content

Commit f77d108

Browse files
committed
feat: add instance.get_classes for template components
1 parent e6ed81f commit f77d108

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

djangocms_frontend/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def add_attribute(self, attr, value=None):
7676

7777
def get_attributes(self):
7878
attributes = self.config.get("attributes", {})
79-
classes = set(attributes.get("class", "").split()) # classes added in attriutes
80-
classes.update(self._additional_classes) # add additional classes
81-
classes = (f'class="{conditional_escape(" ".join(classes))}"') if classes else "" # to string
79+
classes = self.get_classes() # get classes
8280
parts = (
8381
f'{item}="{conditional_escape(value)}"' if value else f"{item}"
8482
for item, value in attributes.items()
@@ -87,6 +85,12 @@ def get_attributes(self):
8785
attributes_string = (classes + " ".join(parts)).strip()
8886
return mark_safe(" " + attributes_string) if attributes_string else ""
8987

88+
def get_classes(self):
89+
attributes = self.config.get("attributes", {})
90+
classes = set(attributes.get("class", "").split()) # classes added in attriutes
91+
classes.update(self._additional_classes) # add additional classes
92+
return conditional_escape(" ".join(classes))
93+
9094
def save(self, *args, **kwargs):
9195
self.ui_item = self.__class__.__name__
9296
return super().save(*args, **kwargs)

docs/source/tutorial/template_components.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ The fields declared earlier (``title``, ``slogan``, and ``hero_image``) are now
196196
<img src="{{ hero_image.url }}">
197197

198198
The ``{% childplugins %}`` block allows additional CMS plugins (like buttons) to be added inside the component
199-
in the structure editor.
199+
in the structure editor. Anything in between ``{% childplugins %}`` and ``{% endchildplugins %}`` will only be
200+
rendered if the component has no children.
201+
200202

201203
Make the component available in django CMS
202204
-------------------------------------------

0 commit comments

Comments
 (0)