Problem/Motivation

We use UI Example to build example pages with the front-end team, which facilitates back-end integration.
Drupal allows you to add classes in the body tag. Some of these are quite useful for front-end development.

For example, user-logged-in, is-front, page-node-type-[bundle]. These classes applied to the body enable global management to be applied to certain pages.
However, UI Examples won't inherit classes like the one added for a node-type-news content type/ is-front.

We could use a preprocess_html but I'm a bit worried about having code specific to the example mixed in with the preprocess linked to the project.

Proposed resolution

Would it be possible to add a mechanism that would add the classes to the body of an example page? Via the "additional" property for example?

Like : <body class="not-front page-node-type-news"></body>

Thanks in advance for your feedback, expertise

Comments

Martygraphie created an issue. See original summary.

grimreaper’s picture

Assigned: Unassigned » pdureau

Hi,

Assigning to @pdureau to get his feedbacks.

Here are mines.

1: Acting on body tag is out of the scope of this module
2: We have added in such classes in UI Suite Bootstrap: https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ..., we did that to ease the theme adoption even if we are against such practices (maybe one day I will be fed up with that and remove it). It should not be a "global" class that impact the components/layouts, etc.
3: The UI Skins theme feature allows to act on the body tag, but it will be global. Maybe you can give a look at how it works and adapt to your needs. Maybe this feature request should be opened on UI Skins, but in this case, I think the issue needs a proper concrete use case/example.

So in my opinion it will be a "Closed (works as designed)".

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Active » Postponed (maintainer needs more info)

1: Acting on body tag is out of the scope of this module

Indeed.

3: The UI Skins theme feature allows to act on the body tag, but it will be global. Maybe you can give a look at how it works and adapt to your needs. Maybe this feature request should be opened on UI Skins, but in this case, I think the issue needs a proper concrete use case/example.

Ye,s we need a proper example to answer this question.

So in my opinion it will be a "Closed (works as designed)".

I agree, but we can first wait for a proper example. Marc-Antoine, can you share?

grimreaper’s picture

Just thinking.

With #3517033: Add a style utility API, I think it will be possible to set:

attached:
  styles:
    my_style: my_option

And with the proposed event subscriber (removed from Core for now, but it could be moved in ui_styles until then) then styles could be attached to body from the render array of the example.