1

I am using layout argument in path but it display with base url like

<block class="Magento\Framework\View\Element\Html\Link"  name="search-mini-text">
                    <arguments>
                        <argument name="label" xsi:type="string" translate="false">Search Products..</argument>
                        <argument name="path" xsi:type="string" translate="false">javascript:void(0)</argument>
                        <argument name="class" xsi:type="string" translate="true">search-mini-text</argument>
                   </arguments>
                </block>

When I add this it display like this

<a href="http://127.0.0.0/demomage230/javascript:void(0)/" class="search-mini-text">Search Products..</a>

Expected result should be

<a href="javascript:void(0)" class="search-mini-text">Search Products..</a>

But i woluld like to display javascript:void(0) instead.

How can i exclude baseurl in path argument

2

You should try with this

 <block class="Magento\Framework\View\Element\Html\Link"  name="search-mini-text">
                    <arguments>
                        <argument name="label" xsi:type="string" translate="false">Search Products..</argument>
                        <argument name="onclick" xsi:type="string" translate="false">return false</argument>
                        <argument name="class" xsi:type="string" translate="true">search-mini-text</argument>
                   </arguments>
                </block>

It will prevent redirecting on click

1

Quick fix would be instead of putting your JS in the path, you can just use the on click attribute.

But if you really want to pass your JS as a href, you are going to modify the logic of the block. Since the getHref method pass the path into getUrl which prepends the base url.

You could either create a custom block that extends Magento\Framework\View\Element\Html\Link and overwrite the getHref method with return $this->getPath() and then reference that new block in your XML.

Or you could create a after plugin for Magento\Framework\View\Element\Html\Link::getHref and check if a custom argument exists such as isPathRelative if it does then just return $this->getPath otherwise return the result from the initial plugin

  • Let me try your way. – MageLerner Jun 13 '19 at 7:42

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.