Move classes out of the preprocess functions and into the Twig templates. Use the addClass() attribute method to add classes in the template. Use the clean_class filter to filter class names, if necessary. Maintain all existing functionality and ensure all existing class names are still in the markup, even ones that are inherited.

See the following issues for more detailed examples:
#2217731: Move field classes out of preprocess and into templates
#2254153: Move node classes out of preprocess and into templates

See this change record for information about using the addClass() method:

See this change record for more information about the phase 1 process of moving class from preprocess to templates:

Preprocess Functions Modified


Twig Templates Modified



davidhernandez’s picture

Issue tags: +FUDK
mortendk’s picture

Issue summary: View changes

the classes for the maintenance pages is only affected on the body tag - so i suggest we move that to html patch instead #2329753: Move html classes from preprocess to templates
i have updated the issue

davidhernandez’s picture

Did you move them to the other issue?

mortendk’s picture

i moved the preprocesses listings over

davidhernandez’s picture

Issue summary: View changes
Sutharsan’s picture

Assigned: Unassigned » Sutharsan
Sutharsan’s picture

Assigned: Sutharsan » Unassigned

views_preprocess_page removes the 'contextual-region' body class if the page content is a view. This is a very specific case which I think should not be replaced with a removeClass() in the template.

bartik_preprocess_page and seven_preprocess_page pass body classes to the html template. A similar situation is discussed in #2329753: Move html classes from preprocess to templates.

I can not come up with a descent in-template alternative for adding classes to 'main_menu' and 'secondary_menu'.

davidhernandez’s picture

Status: Active » Closed (won't fix)

I'm not seeing anything relevant here any more. Most of what we needed was changed in the html issue. preprocess_page isn't adding any classes.

Bartik and Seven are going through their own refactoring, so their changes can be worried about elsewhere. Also, Bartik and Seven changes don't affect core or Classy.