Magento 2 introduced a new node type to its Layout XML DSL — the <arguments/>
and <argument/>
node.
#File: vendor/magento/module-shipping/view/frontend/layout/sales_guest_view.xml
<referenceBlock name="sales.order.view">
<block class="Magento\Shipping\Block\Tracking\Link" name="tracking-info-link" template="Magento_Shipping::tracking/link.phtml">
<arguments>
<argument name="label" xsi:type="string" translate="true">
Track your order
</argument>
</arguments>
</block>
</referenceBlock>
Like so much of Magento — the names of these new nodes hide their purpose from developers. All the <argument/>
nodes do ensure a value will be set on the final block object. i.e. The above code will set a label
property on the tracking-info-link
block (instantiated from the PHP class Magento\Shipping\Block\Tracking\Link
). This means you can access the property from your phtml
template like this
$block->getLabel();
$block->getData('label');
You can see this in the Magento_Shipping::tracking/link.phtml
template file.
#File: vendor/magento/module-shipping/view/frontend/templates/tracking/link.phtml
<span><?= /* @escapeNotVerified */ $block->getLabel() ?></span>
Behind the scenes, this functionality is implemented by Magento looking for these argument nodes, and then passing additional information into the Block class when instantiating a Block object. That’s why these nodes are called <arguments/>
and <argument/>
— because the system designer was focused on the implementation details of the system instead of how end user programmers would use the system.