Magento – Add class to body in CMS page (with layout update xml from admin panel)

cmslayoutmagento-2.1magento2

I'm trying to add a class to body (cms-page-aboutus) via layout XML update inside Magento 2 admin panel.

I know that CMS pages already add a body I could use to target my page, but I need to target multiple CMS pages for several languages at once (cms-about-us, cms-acerca-de, cms-a-propos).

I don't want to duplicate CSS, therefore a common class would be best.

I have tried the following:

<body>
    <attribute name="class" value="body-class" />
</body>

But it fails to save in admin panel:

Please correct the XML data and try again. Element 'body': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 2

Since it seems that only "update" keyword is allowed, I tried using it to add a new handle:

<update handle="cms_page_aboutus"/>

and then created the file:

app/design/<>/<>/Magento_Cms/layout/cms_page_aboutus.xml

with the body update within, but it does not work.

Any idea?

Best Answer

Add these lines to layout in Design > Layout Update XML of cms page:

<body>
    <attribute name="class" value="body-class-aaa" />
</body>