Вопрос

Here is my code to add toplinks in my custom module

<referenceBlock name="header.links">
    <block class="Magento\Framework\View\Element\Html\Link" ifconfig="hello/general/enable" name="hello" >
        <arguments>
            <argument name="label" xsi:type="string">hello</argument>
            <argument name="path" xsi:type="string" translate="false">hello/index/index</argument>
        </arguments>
    </block>
</referenceBlock>

I want to add toplinks only if both option are true.

How to add one more condition for ifconfig="hello/general/toplinkenable" with this block or is there any alternate solution to check both conditions to add toplinks?

Это было полезно?

Решение

ifconfig supports only one value.
In order to solve your problem, I suggest creating your own block that extends Magento\Framework\View\Element\Html\Link and add the conditions in the _toHtml method.

Something like this:

<?php 
namespace Vendor\Module\Block;  

class Link extends \Magento\Framework\View\Element\Html\Link
{
    public function _toHtml() 
    {
        if (
            !$this->_scopeConfig->isSetFlag('hello/general/enable') || 
            !$this->_scopeConfig->isSetFlag('hello/general/toplinkenable')
        ) {
            return '';
        }
        return parent::_toHtml();
    }
}

then include your block in the layout
Instead of this

<block class="Magento\Framework\View\Element\Html\Link" ifconfig="hello/general/enable" name="hello" >

use this

<block class="Vendor\Module\Block\Link" name="hello" >
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top