Normally it should be done with <action />
tag :
<referenceContainer name="content">
<action method="unsetChild" ifconfig="dashboard/settings/remove">
<argument xsi:type="string">dashboard</argument>
</action>
</referenceContainer>
EDIT :
Only problem is unsetChild only accept alias. You cannot use block name.
Other solution: rewrite Magento Framework to be able to use ifconfig with remove="true"
1- Create your own module.
2- Add a new file to override Magento Framework : (eg : /Vendor/Module/Override/Magento/Framework/View/Layout/Reader/Block.php
)
namespace Vendor\Module\Override\Magento\Framework\View\Layout\Reader;
use Magento\Framework\App;
use Magento\Framework\Data\Argument\InterpreterInterface;
use Magento\Framework\View\Layout;
/**
* Block structure reader
*/
class Block extends \Magento\Framework\View\Layout\Reader\Block
{
/**
* @var \Magento\Framework\App\ScopeResolverInterface
*/
protected $scopeResolver;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* Constructor
*
* @param Layout\ScheduledStructure\Helper $helper
* @param Layout\Argument\Parser $argumentParser
* @param Layout\ReaderPool $readerPool
* @param InterpreterInterface $argumentInterpreter
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
* @param string|null $scopeType
*/
public function __construct(
Layout\ScheduledStructure\Helper $helper,
Layout\Argument\Parser $argumentParser,
Layout\ReaderPool $readerPool,
InterpreterInterface $argumentInterpreter,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\ScopeResolverInterface $scopeResolver,
$scopeType = null
) {
parent::__construct($helper,
$argumentParser,
$readerPool,
$argumentInterpreter,
$scopeType
);
$this->scopeConfig = $scopeConfig;
$this->scopeResolver = $scopeResolver;
}
protected function scheduleReference(
Layout\ScheduledStructure $scheduledStructure,
Layout\Element $currentElement
) {
$elementName = $currentElement->getAttribute('name');
$elementRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);
if ($elementRemove) {
$configPath = (string)$currentElement->getAttribute('ifconfig');
if (empty($configPath)
|| $this->scopeConfig->isSetFlag($configPath, $this->scopeType, $this->scopeResolver->getScope())
) {
$scheduledStructure->setElementToRemoveList($elementName);
}
} else {
$data = $scheduledStructure->getStructureElementData($elementName, []);
$data['attributes'] = $this->mergeBlockAttributes($data, $currentElement);
$this->updateScheduledData($currentElement, $data);
$this->evaluateArguments($currentElement, $data);
$scheduledStructure->setStructureElementData($elementName, $data);
}
}
}
3- Add di.xml file to override magento file :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\View\Layout\Reader\Block"
type="Vendor\Module\Override\Magento\Framework\View\Layout\Reader\Block" />
</config>
4- Now you can use ifconfig in layout combined with remove :
<referenceBlock name="content" remove="true" ifconfig="path/to/myconfig" />
This example is for Block, but you can do the same for container if you override the method containerReference() of /Magento/Framework/View/Layout/Reader/Container.php
helper
class, see https://stackoverflow.com/questions/47237179/magento-2-i-want-to-add-ifconfig-in-override-block-xml?rq=1