How to Change Block Arguments in Magento 2
In this post, I’m going to guide you on how to change block arguments in Magento 2.
How to Change Block Arguments
For the block arguments to be modified, the <referenceBlock> instruction is used.
Below is an example of how to change the existing block argument’s value and also add a new argument.
- Initial block declaration:
<block class="Namespace_Module_Block_Type" name="block.example">
<arguments>
<argument name="label" xsi:type="string">Block Label</argument>
</arguments>
</block>
- Extending layout:
<referenceBlock name="block.example">
<arguments>
<!-- Modified block argument -->
<argument name="label" xsi:type="string">New Block Label</argument>
<!- Newly added block argument -->
<argument name="custom_label" xsi:type="string">Custom Block Label</argument>
</arguments>
</referenceBlock>
Conclusion
Above, I have just provided you an instruction on how to modify block arguments in Magento 2 using the <referenceBlock> instruction. I hope it is helpful for you. Should you have any questions or new ideas, feel free to leave a comment below.
Enjoyed the tutorial? Spread it to your friends!
Featured Extensions
-30%
One Step Checkout
$139 ($199)
164 reviews
-30%
Layered Navigation
$69 ($99)
87 reviews
-30%
Automatic Related Products
$139 ($199)
25 reviews
-30%
PDF Invoice
$139 ($199)
23 reviews
-30%
Reward Points
$69 ($99)
14 reviews
-19%
B2B Solution
$465 ($576)
-30%
Product Feed
$104 ($149)
16 reviews