@@ -96,6 +96,9 @@ Avoid extending this template class, because with inheriting the template block
96
96
If you need custom presentation logic in your blocks, use this class as block, and declare
97
97
custom view models in block arguments in layout handle file.
98
98
99
+ View model parameter can have any name.
100
+ Also, one block can have multiple view models injected via layout.
101
+
99
102
Example:
100
103
101
104
``` xml
@@ -109,7 +112,7 @@ Example:
109
112
In template, access your model instead of the block:
110
113
111
114
``` php
112
- $viewModel = $block->getViewModel( );
115
+ $viewModel = $block->getData('viewModel' );
113
116
```
114
117
115
118
[ 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
134
137
135
138
`_beforeToHtml`:
136
139
- can't change page title?
137
- - some block are rendered, can't change them
140
+ - some blocks are rendered, can't change them
138
141
- 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
140
143
141
144
`_toHtml`:
142
145
- block without template, put custom rendering here, e.g. calling external API
0 commit comments