如何从帮助程序获取布局中路径参数的输出?


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>

我正在default.xml中尝试此操作。我如何从助手操作中获取字符串作为path参数?

Answers:


11

尝试:

<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>

您也可以像这样传递方法的参数:

<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)例如:您在Data.php中的Namespace / Modulename / Helper中具有getTitle()函数

<?php

namespace Namespace\Modulename\Helper;

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

}

2)在layout.xml中,将xsi:type =“ string”更改为xsi:type =“ helper”并定义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>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.