0

I am trying to add a phtml template file to the layout file so that I can use this template in the head section to insert contents from an JS file. Please tell me what is the best way to do this?

1 Answer 1

0

check below XML code

I have created a custom theme and create a default layout in the theme. I have added a template to head using below XML code.

<referenceContainer name="head.additional">
            <block class="Custom\Theme\Block\Template" name="custom_head" template="html/head.phtml" before="-"/>
</referenceContainer>
12
  • Thanks. Please tell me where to place this code? Commented May 11, 2020 at 7:11
  • i have added code in layout/default.xml.
    – Devidas
    Commented May 11, 2020 at 7:16
  • top of file after <body> tag
    – Devidas
    Commented May 11, 2020 at 7:16
  • Okay, I don't have "layout/default.xml" directory under my custom theme. What should I do? Commented May 11, 2020 at 7:18
  • first override default.xml file in your theme. please google it
    – Devidas
    Commented May 11, 2020 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.