Currently, CSS and JS added in head section default_head_blocks.xml.

But I want to add in the footer. In which I need to put the css and js?


As the css and script layout xml tag will only work inside head I think you'll need to create a block as a child of before.body.end and load your CSS/JS files manually there.

Alternatively you could do that directly in layout XML like this:

<referenceContainer name="before.body.end">
    <block class="Magento\Framework\View\Element\Text" name="exampleScript">
            <argument name="text" xsi:type="string"><![CDATA[<script type="text/javascript" src="//www.example.com/example-script.js"></script>]]></argument>

Although that wouldn't work well for local assets as you'd have to hard code the pub/media URL which wouldn't work if you have versioning enabled.

| improve this answer | |

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.