Skip to content

Commit 3e01541

Browse files
authored
Merge pull request #18 from snowcore/fix/blocks
Some fixes and improvements for blocks section
2 parents d3eea58 + bd1783e commit 3e01541

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

3. Customizing the Magento UI/2. Determine how to use blocks.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ Avoid extending this template class, because with inheriting the template block
9696
If you need custom presentation logic in your blocks, use this class as block, and declare
9797
custom view models in block arguments in layout handle file.
9898

99+
View model parameter can have any name.
100+
Also, one block can have multiple view models injected via layout.
101+
99102
Example:
100103

101104
```xml
@@ -109,7 +112,7 @@ Example:
109112
In template, access your model instead of the block:
110113

111114
```php
112-
$viewModel = $block->getViewModel();
115+
$viewModel = $block->getData('viewModel');
113116
```
114117

115118
[ViewModels in Magento 2](https://www.yireo.com/blog/1856-viewmodels-in-magento-2)
@@ -134,9 +137,9 @@ At this stage all blocks in layout are generated, but _prepareLayout is only run
134137

135138
`_beforeToHtml`:
136139
- can't change page title?
137-
- some block are rendered, can't change them
140+
- some blocks are rendered, can't change them
138141
- assign additional template values
139-
- delay computation to latest point until render. if block is not rendered we save computation
142+
- delay computation to the latest point until render. If block is not rendered we save computation
140143

141144
`_toHtml`:
142145
- block without template, put custom rendering here, e.g. calling external API

0 commit comments

Comments
 (0)