Feature idea: Page class attribute

13 views
Skip to first unread message

Brian Rutledge

unread,
Nov 17, 2016, 10:54:43 AM11/17/16
to django CMS developers
In our templates, I'd like to be able to identify a page as being part of a section of the site, so that we can apply section-specific CSS. My initial thought on how to do this would be to add a class to the <body> tag, but I don't see an attribute on the Page model for this. What do y'all think of adding that? Is there another way to accomplish this in the django CMS ecosystem? I'd rather not define a new template for each section.

czpython

unread,
Nov 17, 2016, 10:57:23 AM11/17/16
to django CMS developers
Hello Brian,

You can use https://github.com/nephila/djangocms-page-tags for tagging pages
or build a custom solution using page extensions.

Daniele Procida

unread,
Nov 18, 2016, 4:10:51 AM11/18/16
to django CMS developers
I've done this with another application. It maintained a tree representing the structure of an institution, and each node of that tree could be attached to a page. So each page, and all of its descendants, knew they belonged to such-and-such department or office or body.

The application did a lot more besides. It might be overkill if identifying a page is all you need.

Daniele

Brian Rutledge

unread,
Nov 18, 2016, 10:18:26 AM11/18/16
to django CMS developers
Thanks for the ideas. I think djangocms-page-tags or a page extension is the right approach, but for now, I've got:

<body data-cms-path="{{ request.current_page.get_path }}">

which renders the attribute value as "section-1/subsection-1/page-1". So, in my CSS, I can use:

[data-cms-path*="subsection-1"] {
}

to style section elements. Of course, this will break of the slugs change, or if they're different in Spanish, or if a section page exists outside of the tree. But it works for now.
Reply all
Reply to author
Forward
0 new messages