Hi everyone.
I am going through hard times. After the latest updates, there is no more the Layout Update XML field in the admin panel (Magento 2.3.4).
I needed to create a custom layout for some types of cms pages, so I thought of creating one by adding to my child theme:
/app/design/frontend/Vendor/Theme/Magento_Theme/page_layout/examplepage.xml
containing:
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd"> <head> <css src="css/csspagine.css"/> </head> <referenceContainer name="sidebar.additional"> <block class="Magento\Cms\Block\Block" name="exampleblock"> <arguments> <argument name="block_id" xsi:type="string">exampleblock</argument> </arguments> </block> </referenceContainer> </layout>
and under /app/design/frontend/Vendor/Theme/Magento_Theme/page_layout/layouts.xml
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
<layout id="examplepage">
<label translate="true">Page Example</label>
</layout>
</page_layouts>
finally I added the css file csspagine.css
/app/design/frontend/Vendor/Theme/web/css/
The pages are correctly set in the magento backend, but the css is not loaded. I can't find a solution. Can you help me?
It is important for me that this Css is loaded only on this group of pages and not on the whole site.
thank you all
Hello @Pellein
Try to replace <css src="css/csspagine.css"/> with
<css src="Magento_Theme::css/csspagine.css"/>
OR
Add css to specific CMS Page than create xml like:
cms_page_view_id_[cms_page_url].xml
For example,
cms_page_view_id_home.xml
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <head> <css src="Magento_Theme::css/csspagine.css"/> </head> </page>
I hope it helps.
Hi Sanjay Jethva
Thanks for the reply
I tried adding: <css src="Magento_Theme::css/csspagine.css"/> instead of <css src="css/csspagine.css"/>
Unfortunately it doesn't work, the css is not loaded.
The solution of adding the css to the page and renaming the xml like this "cms_page_view_id_[cms_page_url].xml" file instead works.
Unfortunately in doing so, I would have to create many xml pages, one for each store view and every time I would add a page, also in the future I would have to create an xml page just to load a portion of css code that I would not like to show on the other pages of the site.
It seems like a very cumbersome thing.
I still haven't been able to find a solution for this It's frustrating.
cms_page_view_id_yourpageurl.xml
Thank you this worked for me after searching long!!