-1

In my page-template there is a header, footer and div for the content.

The page-template is used to put menu and footer stuff in that comes back on every page...

But on some pages the header should have a other background... try to realise that with just adding a different class on that header.

But I wonder how I can put a different class on the header in page.html.twig depending on the sort of type content that was used.

Example: So for the home page a created the content type 'home page'... for the other page i created the content type 'normal page' so how can I put different classes into the page template depending on the content type that created a page?

What is the best way to do this...

Thanks for reading!

0

As you have created new content types, the body tag of your new content type should have a class based on your new content types, like 'node-type-CONTENT_TYPE'. You can use this class to change the background of your footer and header. .node-type-CONTENT_TYPE .footer

  • Best answer I think... because quick solution... the class is already there... I forgot this! Thanks man! love solutions like this ;-) – Mr. Save Jan 12 '18 at 10:48
  • I tried this solution today.. but seems to be there are no classes on the body tag... Can I activate content-type classes on the body tag... or should I install a extra module for that? – Mr. Save Jan 15 '18 at 11:33
  • Hi, I added this code to the body tag {{ attributes.addClass(body_classes) }} but the classes don't show up... – Mr. Save Jan 15 '18 at 11:43
  • Hm.. this is strange. Did you create custom twig file where you removed the default functionality? The body attributes are defined in the html.html.twig file. Do you have a custom one? – Ismini Jan 15 '18 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.