0

I am trying to create dynamic head using phtml on Magento 2.3.5 p1.

I am inserting in default.xml the following:

<page>
<body>   
...
 <referenceContainer name="head.additional">
        <block class="Magento\Framework\View\Element\Template" name="custom_head_file" template="Magento_Theme::custom_head.phtml"/>
    </referenceContainer>
...
</body>
</page>

The output of custom_head.phtml is showing inside the BODY and not inside the HEAD.

Any ideas on how can this be debugged and corrected? I also tried refereceBlock and the result is the same.

2
  • I just try your code and it is correct and phtml connect showing just before </head> – Pawan Dec 29 '20 at 3:02
  • Please make sure your default.xml is being processed by Magento – Vivek Kumar Dec 29 '20 at 6:58
0

My bad. The problem was not in the default.xml, but in the content in the custom_head.phtml.

I had originally

echo "testing";

Once i changed the content of custom_head.phtml as shown under it works.

echo "<link rel='dns-prefetch' href='//www.google.com/'>";

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.