Làm thế nào để có được đầu ra từ trình trợ giúp cho đối số đường dẫn trong bố cục?


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>

Tôi đang thử cái này trong default.xml. Làm thế nào tôi có thể nhận được một chuỗi từ hành động trợ giúp cho pathđối số?

Câu trả lời:


10

Thử:

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

Bạn cũng có thể truyền tham số cho phương thức như thế này:

<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) Ví dụ: bạn có chức năng getTitle () trong Data.php tại Namespace / Modulename / Helper

<?php

namespace Namespace\Modulename\Helper;

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

}

2) Trong layout.xml, thay đổi xsi: type = "string" thành xsi: type = "helper" và định nghĩa lớp helper :: 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>
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.