禁用/启用magento 2中管理面板的自定义前端页脚链接

时间:2017-04-04 10:59:43

标签: frontend magento2 adminhtml

我有一个自定义模块,在前端的页脚部分显示自定义链接。 然后,我在管理面板中有我的模块特定配置。

我想通过管理面板中的配置禁用/启用前端页脚的链接。

我怎样才能做到这一点?请帮忙。

我在view / frontend / layout / default.xml

中的前端添加了页脚链接
    <referenceBlock name="footer_links">
    <block class="Magento\Framework\View\Element\Html\Link\Current" name="Name">
        <arguments>
            <argument name="label" xsi:type="string">My custom link</argument>
            <argument name="path" xsi:type="string">path/to/link</argument>
        </arguments>
    </block>

我的system.xml就像,

    <!--For creating section -->
<section id="quotes" translate="label" type="text" sortOrder="320" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Module</label>

    <!--Assign section to tab -->
    <tab>mytab</tab>
    <resource>Vendor_Module::configuration</resource>

    <!--create group for fields in section -->
    <group id="quotes" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>Group Name</label>

        <!--create text type field -->
        <field id="enabled" translate="label comment" sortOrder="7" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Enable the link</label>
            <comment>select from the dropdown</comment>

            <!-- source model which we created for drop down options -->
            <source_model>Vendor\Module\Model\Config\Source\Module</source_model>
        </field>
    </group> 
</referenceBlock>   

Vendor \ Module \ Model \ Config \ Source \ Module包含,

public function toOptionArray() {
return [
    ['value' => 'Yes', 'label' => __('Yes')],
    ['value' => 'No', 'label' => __('No')],
 ];
}

1 个答案:

答案 0 :(得分:1)

请使用下面提到的阻止禁用/启用前端页脚上的链接:

<block ifconfig="quotes/quotes/enabled" class="Magento\Framework\View\Element\Html\Link\Current" name="Name">
    <arguments>
        <argument name="label" xsi:type="string">My custom link</argument>
        <argument name="path" xsi:type="string">path/to/link</argument>
    </arguments>
</block>

报价字段应该是YES和NO下拉。 当引号字段为YES时,它将显示,否则将不显示。