Adding and deleting static resources

    To add static resource in page like stylesheet (style.css) or external style sheet defaine a node <head> either in default.xml in your module or you can add it into theme xml file default_head_blocks.xml


    You can add a css file using the following instruction:

    <css src="css/my-styles.css"/>

    To add a locally hosted JavaScript file, you can use one of the following instructions:

    <script src="Magento_Catalog::js/sample1.js"/>
    <link src="js/sample.js"/>

    In order to get external resource, you should add the src_type attribute with the url value. For example:

    <css src="" src_type="url" />
    <script src="" src_type="url" />

    To add Font

    Use a mandatory addition of the rel=”stylesheet” and type=”text/css”:

    <link rel="stylesheet" type="text/css" src="" src_type="url" />

    Adding a new containers

    <container name="" as="yourContainer" label="Any container Label" htmlTag="div" htmlClass="my-container-class" />

    To change Reference containers (For adding a block)

    <referenceContainer name="header.panel">
       <block class="YouVendor\YouModule\Block\AnyBlock" name="name.of.block" />

    To Add a block

    <block class="Magento\Catalog\Block\Product\View\Description" name="" template="product/view/yourfile.phtml" after="" />

    To Add a Refernceblock

    <referenceBlock name="new.template" template="Your_Module::yourtemplatefile.phtml"/>


    <referenceBlock name="new.template">
            <argument name="template" xsi:type="string">Your_Module::new_template.phtml</argument>

    About Author

    You may also like

    No Comment

    You can post first response comment.

    Leave A Comment

    Please enter your name. Please enter an valid email address. Please enter a message.