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
First, you need to modify the targeted block arguments you are going to change.
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
That’s all. 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. If you have any questions or new ideas, feel free to leave a comment below.
Thanks for reading!
Enjoyed the tutorial? Spread it to your friends!
Featured Extensions
Salesforce CRM Integration
$349
5 reviews
-20%
Sales Booster
$318 ($397)
-20%
Marketing Solution
$278 ($347)
-25%
B2B Solutions
$641 ($854)
4 reviews
Free
Social Login
$0
175 reviews
Free
PWA-ready
API-GraphQL
Better Blog
$0
123 reviews
API-GraphQL
GDPR
$79
33 reviews
GeoIP
$149
8 reviews