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" >
            <argument name="label" xsi:type="string">hello</argument>
            <argument name="path" xsi:type="string" translate="false">hello/index/index</argument>

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:

namespace Vendor\Module\Block;  

class Link extends \Magento\Framework\View\Element\Html\Link
    public function _toHtml() 
        if (
            !$this->_scopeConfig->isSetFlag('hello/general/enable') || 
        ) {
            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" >

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.