An Adobe Commerce developer is using a view model within an existing block:
What are two ways to access the view model class in the template? (Choose two.)
To access a view model within an existing block, the developer can use either of the following ways:
$block->getData('view_model'): This method will return the view model object that is assigned to the argument name ''view_model'' in the layout XML file. For example:
<referenceBlock name=''blog_posts_list''>
In the template file, the developer can access the view model object by using:
$block->getData('view_model')
$block->getData('viewModel'): This method will return the view model object that is assigned to the argument name ''viewModel'' in the layout XML file. For example:
<referenceBlock name=''blog_posts_list''>
In the template file, the developer can access the view model object by using:
$block->getData('viewModel')
The following methods are not valid and will not work:
$block->viewModel(): This method does not exist and will cause an error.
$block->getViewHodel(): This method is misspelled and will cause an error.
Steffanie
3 months agoOretha
3 months agoLashon
3 months agoReita
2 months agoQuentin
2 months agoMalcom
2 months agoPrecious
2 months agoRebecka
3 months agoArt
3 months agoKallie
3 months agoPete
3 months agoGilma
3 months agoTequila
3 months agoSon
3 months agoElinore
3 months agoDaron
3 months agoDierdre
3 months agoRicki
3 months agoShawnda
3 months agoStefania
3 months agoLino
4 months ago