I've followed the DevDoc on How to Add a JavaScript Module (Magento 2.2) and it works fine. However, I can't get it to work on my Magento site homepage. I added
/app/code/Learning/Js/view/frontend/layout/cms_index_index.xml
with the same code as the sample catalog_product_view.xml
and I can see that the relevant code appears in my homepage source viewed from a browser. However, the JavaScript fails to run.
catalog_product_view.xml / cms_index_index.xml
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" template="Learning_Js::hello.phtml" />
</referenceContainer>
</body>
</page>
You can view the test site homepage at http://magento.onlinekit.co.uk/ and the working Module at http://magento.onlinekit.co.uk/surridge-adult-century-3-4-sleeve-cricket-shirt (it displays a 'Hello World' alert).
Any help would be appreciated.