0

I'm trying to add a tel: href to a footer with the next code:

 <block class="Magento\Framework\View\Element\Html\Link" name="telefon">
                            <arguments>
                                <argument name="label" xsi:type="string" translate="true">0728 947 887
                                </argument>
                                <argument name="path" xsi:type="string">tel:0728947887</argument>          
                            </arguments>
                        </block>

The link generates but it comes like: https://domain.com/tel:0728947887

In order for the tel: to work, I simply need it to be tel:0728947887

I also tried adding this to the block but the href did not change:

 <argument name="attributes" xsi:type="array">
                                    <item name="href" xsi:type="string">tel:0728947887</item>
                                </argument>

I'd appreciate any ideas, thanks!

1 Answer 1

2

unfortunately all footer links added via layout xml generate urls prefixed with base url because of this method : Magento\Framework\View\Element\Html\Link::getHref().
But the workaround is to create a phtml template and assing it to your block. then you should be able to render the link as you wish.

Create the template called phone.phtml in one of your modules and change the layout xml to this

 <block class="Magento\Framework\View\Element\Html\Link" name="telefon" template="Vendor_Module::phone.phtml">
      <arguments>
         <argument name="label" xsi:type="string" translate="true">0728 947 887</argument>
         <argument name="path" xsi:type="string">tel:0728947887</argument>          
       </arguments>
 </block>

The template file can look like this:

<li>
     <a href="<?= $block->escapeHtmlAttr($block->getPath()) ?>">
         <?= $block->escapeHtml($block->getLabel());?>
     </a>
</li>

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.