Doc officielle: Layout instructions
Le truc à retenir est que les attributs before
et after
applicables sur les balises container
et block
des layouts XML de Magento 2 ont BESOIN d’un contexte pour fonctionner. Exemple:
Pas bon:
L’attribut before
ne fonctionnera PAS! Votre block cart.product.slider
ne s’affichera pas ou s’affichera au mauvais endroit (ou au bon endroit sur un malentendu… jusqu’à la prochaine modification de layout que vous effectuerez).
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <update handle="checkout_cart_item_renderers"/> <body> <container name="cart.product.slider.container" htmlTag="div" htmlClass="page-bottom" before="page.bottom.container"> <block class="Magento\Cms\Block\Block" name="cart.product.slider"> <arguments> <argument name="block_id" xsi:type="string">cart-product-slider</argument> </arguments> </block> </container> </body> </page> |
Bon:
L’attribut before
fonctionnera!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <update handle="checkout_cart_item_renderers"/> <body> <referenceContainer name="content"> <container name="cart.product.slider.container" htmlTag="div" htmlClass="page-bottom" before="page.bottom.container"> <block class="Magento\Cms\Block\Block" name="cart.product.slider"> <arguments> <argument name="block_id" xsi:type="string">cart-product-slider</argument> </arguments> </block> </container> </referenceContainer> </body> </page> |
Vous avez saisi la différence entre les deux samples de code ci-dessus?
La ligne <referenceContainer name="content">
précise un contexte, une parenté. Les containers cart.product.slider.container
et page.bottom.container
sont des enfants directs du container content
.