10
<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="custommodule/general/enable_footer_link" name="custommodule-link">
<arguments>
    <argument name="label" xsi:type="string">Custom Module</argument>
    <argument name="path" xsi:type="string" helper="NS\CustomModule\Helper\Data::getFrontName()"/>
</arguments>
</block>

I'm trying this in default.xml. how can i get a string from helper action for the path argument?

2 Answers 2

11

Try:

<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="custommodule/general/enable_footer_link" name="custommodule-link">
    <arguments>
        <argument name="label" xsi:type="string">Custom Module</argument>
        <argument name="path" xsi:type="helper" helper="NS\CustomModule\Helper\Data::getFrontName"/>
    </arguments>
</block>

You can also pass parameters for the method like this:

<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="custommodule/general/enable_footer_link" name="custommodule-link">
    <arguments>
        <argument name="label" xsi:type="string">Custom Module</argument>
        <argument name="path" xsi:type="helper" helper="NS\CustomModule\Helper\Data::getFrontName">
            <param name="name">value</param>
        </argument>
    </arguments>
</block>
1

1) For ex: you have function getTitle() in Data.php at Namespace/Modulename/Helper

<?php

namespace Namespace\Modulename\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public function getTitle()
    {
       return "Testing";
    }

}

2) In layout.xml change xsi:type="string" to xsi:type="helper" and define helper class::methodName

<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="custommodule/general/enable_footer_link" name="custommodule-link">
<arguments>
    <argument name="label" xsi:type="string">Custom Module</argument>
    <argument name="path" xsi:type="helper" helper="Namespace\Modulename\Helper\Data::getTitle"/>
</arguments>
</block>

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.