Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This topic discusses how to use custom a hawksearch.js file hosted on Hawksearch server for the purpose of providing custom JS implementations.

We strongly recommend that you do not change the source code of default Hawksearch and Magento components. All customizations must be implemented in custom modules or themes.

Add a custom layout

Place the custom layout file in the following location:

  1. Your theme layout files: <theme_dir>/HawkSearch_Proxy/layout. In this case the layout is available in your theme and its child themes.

Create a layout file default.xml, having specified the following:

<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">
                <arguments>
                    <argument name="configViewModel" xsi:type="object">HawkSearch\Proxy\ViewModel\Config</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

Override hawksearch.js source location

Place the custom .phtml file in the following location:

  1. Your theme templates files: <theme_dir>/HawkSearch_Proxy/templates.

Create a template file hawksearchjs.phtml, having specified the following:

<?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;
}
?>
<script type="text/javascript">
    (function() {
        var config = {
            paths: {
                "HawkSearch_Proxy/js/hawksearch": "<?= /* @noEscape */ $configViewModel->getHawkUrl('includes/hawksearch') ?>"
            }
        };
        require.config(config);
    })();
</script>

  • No labels