Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 3a9e938

Browse files
authored
Merge pull request #5445 from eduard13/patch-layout-block-ifconfig
Improving the layout common customization with block ifconfig argument
2 parents deab5a4 + 9c7d83b commit 3a9e938

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

guides/v2.2/frontend-dev-guide/layouts/xml-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ We recommend always adding a `name` to blocks. Otherwise, it is given a random n
7070
| `template` | A template that represents the functionality of the block to which this attribute is assigned. | template file name | no |
7171
| `as` | An alias name that serves as identifier in the scope of the parent element. | 0-9, A-Z, a-z, underscore (_), period (.), dash (-). Case-sensitive. | no |
7272
| `cacheable` | Defines whether a block element is cacheable. This can be used for development purposes and to make needed elements of the page dynamic. | `true` or `false` | no |
73+
| `ifconfig` | Makes the block's visibility dependent on a system configuration field. | XPath to the system configuration field. E.g. `contact/contact/enabled` | no |
7374

7475
To pass parameters use the [`<argument></argument>`](#argument) instruction.
7576

guides/v2.2/frontend-dev-guide/layouts/xml-manage.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This article describes the following typical [layout](https://glossary.magento.c
1616
- [Create a container](#create_cont)
1717
- [Reference a container](#ref_container)
1818
- [Reference a CMS block](#ref_cms_block)
19+
- [Making the block visibility dynamic](#ref_config_block)
1920
- [Create a block](#xml-manage-block)
2021
- [Set the template used by a block](#set_template)
2122
- [Modify block arguments](#layout_markup_modify-block)
@@ -236,6 +237,16 @@ As a result, the CMS block is added to the bottom of the page.
236237

237238
![CMS Block]({{ site.baseurl }}/common/images/cms-block-reference.png)
238239

240+
## Making the block visibility dynamic {#ref_config_block}
241+
242+
Any block can be configured to show or not based on a [Magento/Config/Model/Config/Source/Yesno] system configuration field, using the `ifconfig` argument. For the value, use the XPath to the needed field.
243+
244+
```xml
245+
<block class="Namespace\Module\Block\Type" name="block.example" ifconfig="my/yesno/field">
246+
...
247+
</block>
248+
```
249+
239250
## Set the template used by a block {#set_template}
240251

241252
There are two ways to set the template for a block:
@@ -594,3 +605,4 @@ class Product
594605
[`<move>` instruction]: {{page.baseurl}}/frontend-dev-guide/layouts/xml-instructions.html#fedg_layout_xml-instruc_ex_mv
595606
[`before` and `after` attributes of `<block>`]: {{page.baseurl}}/frontend-dev-guide/layouts/xml-instructions.html#fedg_xml-instrux_before-after
596607
[Magento/Cms/Block/Block]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Cms/Block/Block.php
608+
[Magento/Config/Model/Config/Source/Yesno]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Config/Model/Config/Source/Yesno.php

guides/v2.3/frontend-dev-guide/layouts/xml-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ We recommend always adding a `name` to blocks. Otherwise, it is given a random n
6767
| `template` | A template that represents the functionality of the block to which this attribute is assigned. | template file name | no |
6868
| `as` | An alias name that serves as identifier in the scope of the parent element. | 0-9, A-Z, a-z, underscore (_), period (.), dash (-). Case-sensitive. | no |
6969
| `cacheable` | Defines whether a block element is cacheable. This can be used for development purposes and to make needed elements of the page dynamic. | `true` or `false` | no |
70+
| `ifconfig` | Makes the block's visibility dependent on a system configuration field. | XPath to the system configuration field. E.g. `contact/contact/enabled` | no |
7071

7172
To pass parameters use the [`<argument></argument>`](#argument) instruction.
7273

guides/v2.3/frontend-dev-guide/layouts/xml-manage.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This article describes the following typical [layout](https://glossary.magento.c
1616
- [Create a container](#create_cont)
1717
- [Reference a container](#ref_container)
1818
- [Reference a CMS block](#ref_cms_block)
19+
- [Making the block visibility dynamic](#ref_config_block)
1920
- [Create a block](#xml-manage-block)
2021
- [Set the template used by a block](#set_template)
2122
- [Modify block arguments](#layout_markup_modify-block)
@@ -236,6 +237,16 @@ As a result, the CMS block added to the bottom of the page.
236237

237238
![CMS Block]({{ site.baseurl }}/common/images/cms-block-reference.png)
238239

240+
## Making the block visibility dynamic {#ref_config_block}
241+
242+
Any block can be configured to show or not based on a [Magento/Config/Model/Config/Source/Yesno] system configuration field, using the `ifconfig` argument. For the value, use the XPath to the needed field.
243+
244+
```xml
245+
<block class="Namespace\Module\Block\Type" name="block.example" ifconfig="my/yesno/field">
246+
...
247+
</block>
248+
```
249+
239250
## Set the template used by a block {#set_template}
240251

241252
There are two ways to set the template for a block:
@@ -597,3 +608,4 @@ You can remove navigation links from the 'My Account' dashboard on the storefron
597608
[`<move>` instruction]: {{page.baseurl}}/frontend-dev-guide/layouts/xml-instructions.html#fedg_layout_xml-instruc_ex_mv
598609
[`before` and `after` attributes of `<block>`]: {{page.baseurl}}/frontend-dev-guide/layouts/xml-instructions.html#fedg_xml-instrux_before-after
599610
[Magento/Cms/Block/Block]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Cms/Block/Block.php
611+
[Magento/Config/Model/Config/Source/Yesno]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Config/Model/Config/Source/Yesno.php

0 commit comments

Comments
 (0)