cancel
Showing results for 
Search instead for 
Did you mean: 

How to add css and js for specified page layout

How to add css and js for specified page layout

Hi,

I have created a custom cms page layout and I need to add css and js only for this layout.

I tried below tutorial but I am getting fatal error when I click 'Insert widget' from admin->cms page editor->insert widget.

Screenshot_1.jpg

tutorial link : https://magento.stackexchange.com/questions/328115/magento-2-add-css-js-to-custom-layout-only-appli...

2 REPLIES 2

Re: How to add css and js for specified page layout

@sainulabidnv 

You can add your CSS and JS file name here in the head.

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="VendoreName_CustomLayout::css/file.css" />
        <script src="VendoreName_CustomLayout::js/file.js" />
    </head>
</page>
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: How to add css and js for specified page layout

@Sanjay JethvaI need to add the css and js only in custom CMS Page layout not globally. I think the above xml will add the css and js in globally which means all pages.