如您所知,我们可以使用 ifconfig 参数根据 Magento / Config / Model / Config / Source / Yesno 配置字段配置任何块是否显示。对于值,我们可以将 XPath 用于必填字段: 

<block class="Namespace\Module\Block\Type" name="block.example" ifconfig="my/yesno/field">
    ...
</block>

例如:您使用 ifconfig 在核心联系人模块中检查演示: 

供应商/magento/module-contact/view/frontend/layout/default.xml

<referenceBlock name="footer_links">
   <block class="Magento\Framework\View\Element\Html\Link\Current"
ifconfig="contact/contact/enabled" name="contact-us-link">
       <arguments>
           < argument name="label" xsi:type="string"
translate="true">联系我们</argument>
           <argument name="path" xsi:type="string">联系方式</argument>
       </arguments>
   < /block>
</referenceBlock>

 

我们还通过 ACL 资源调整可见性。虽然它主要用于管理区域,但类似的方法也适用于网站的前端。

<block class="Namespace\Module\Block\Type" name="block.example"
aclResource="Vendor_ModuleName::acl_name">
    <!-- ... -->
</block>