1

When adding in my custom scrpts (JS and CSS), I add in <css src="css/custom-styles.css" after="-"/> or <link src="js/custom-js.js" /> in the default_haed_blocks.xml file. I have a PHP script which will generate some dynamic meta information, but how would I include it in every page like the CSS and JS files?

2

You can in layout default.xml write this code:

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="head.additional">
            <block class="Magento\Framework\View\Element\Template" name="block_name" template="path_to_file.phtml" />
        </referenceContainer>
    </body>
</page>

and put content from your script to .phtml template.

Hope this helps

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.