04.07.2019 Views

frontend-developer-1

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Layout XML in Themes<br />

The above example will include a new logic class (using the recommended<br />

Template Block + ViewModel approach) to render additional product details.<br />

The template from this example is automatically rendered to the page within the<br />

container product.info.type.<br />

Blocks<br />

Blocks are a foundational building unit for layout in Magento. They are the link<br />

between a PHP block class, which contains logic and a template which renders<br />

content. Blocks can have children and grandchildren (and so on). Information can<br />

be passed from layout XML into the block via the child node. For<br />

those of a hybrid discipline (backend <strong>developer</strong>s) this could include view models or<br />

some static values to be utilized in the template.<br />

Notable block attributes (more)<br />

• class: defaults to \Magento\Framework\View\Element\Template and does<br />

not need to be specified. In fact, Magento recommends against specifying<br />

a class (see note in the header comments for the Template class in case the<br />

block only is required to output a template).<br />

• name: used to interact with the block from other locations in the <strong>frontend</strong>.<br />

• before / after: places the block before or after another element, as<br />

identified by its name. Or, you can specify a “-” (dash) to place the block at<br />

the beginning or end respectively.<br />

• template: the path to the template. You should always use Magento<br />

module path notation. Example: SwiftOtter_Hero::hero.phtml. If the<br />

Copyright © 2018, SwiftOtter, Inc.<br />

24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!