...
Code Block | ||
---|---|---|
| ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="head.additional"> <block class="Magento\Framework\View\Element\Template" name="hawksearch_js_custom" as="hawksearch_js_custom" template="HawkSearch_Proxy::hawksearchjs.phtml" ifconfig="hawksearch_proxy/general/enabled"> <arguments> <argument name="configViewModel" xsi:type="object">HawkSearch\Proxy\ViewModel\Config</argument> </arguments> </block> </referenceBlock> </body> </page> |
...
Create a template file hawksearchjs.phtml
, having specified the following:. Specify full or minified version of hawksearch.js file in $jsPath
variable
Code Block | ||
---|---|---|
| ||
<?php use Magento\Framework\View\Element\Template; use HawkSearch\Proxy\ViewModel\Config as ConfigViewModel; /** @var Template $block */ /** @var ConfigViewModel $configViewModel */ $configViewModel = $block->getData('configViewModel'); if (!$configViewModel) { return; } $jsPath = 'includes/hawksearch';//Use value 'includes/hawksearch.min' for minified file version ?> <script type="text/javascript"> (function() { var config = { paths: { "HawkSearch_Proxy/js/hawksearch": "<?= /* @noEscape */ $configViewModel->getHawkUrl('includes/hawksearch'$jsPath) ?>" } }; require.config(config); })(); </script> |
...