1

Adding external link in custom theme in any xml e.g: contact_index_index.xml doe not parse properly if it has & or &

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;callback=initMap" src_type="url" />

Notice the &amp; gives:

{"0":"Warning: simplexml_load_string(): Entity: line 6371: parser error : EntityRef: expecting ';' in \/var\/www\/vhosts\/magento2 \/htdocs\/vendor\/magento\/framework\/View\/Model\/Layout\/Merge.php

Does anyone experiencing this too and how to fix it?

Thanks.

2 Answers 2

1

The only way that I found it works is by using head.aditional:

e.g

        <referenceBlock name="head.additional">
            <block class="Magento\Framework\View\Element\Text" name="my_script">
                <action method="setText">
                    <argument translate="true" name="text" xsi:type="string">
                        <![CDATA[<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;callback=initMap" src_type="url" />]]>
                    </argument>
                </action>
            </block>
        </referenceBlock>
0

Try this one :

<?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">
<head>
    <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;callback=initMap" src_type="url"/>
</head>
</page>
2

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.