1

I want to load css file only in home page alone.

I have tried with this way,but it loads on every page.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="Banners::css/banners.css" />
    </head>
</page>

Please let me know how to add condition in layout xml file like we do on old magento layout file

 <catalog_product_view translate="label">
        <reference name="head">
            <action method="addJs"><script>varien/product.js</script></action>
            <action method="addJs"><script>varien/product_options.js</script></action>
            <action method="addJs"><script>varien/configurable.js</script></action>
        </reference>
 </catalog_product_view>
1

got to app/code/Namespace/ModuleName/view/frontend/layout and create

cms_index_index.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="Namespace_ModuleName::css/banners.css"/>

    </head> 
 </page>
0

Create CSS file into below directory.

app/code/Namespace/ModuleName/view/frontend/web/css/web/circle.css

Create the Layout file into below directory.

app/code/Namespace/ModuleName/view/frontend/layout/cms_index_index.xml

Add below code in cms_index_index.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="Namespace_ModuleName::css/circle.css" />
  </head>
</page>
0

Create layout file to app/code/Vendor/Module/view/frontend/layout/cms_index_index.xml with below code

<?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="Namespace_ModuleName::css/banners.css" />
    </head>
</page>

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.