Magento 2: How to add a new phtml(template) to a layout file so I can use it in the head section?

magento.stackexchange https://magento.stackexchange.com/questions/312432

Вопрос

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?

Это было полезно?

Решение

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>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top