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
7 months agoOretha
7 months agoLashon
7 months agoReita
6 months agoQuentin
6 months agoMalcom
6 months agoPrecious
7 months agoRebecka
7 months agoArt
7 months agoKallie
7 months agoPete
7 months agoGilma
8 months agoTequila
7 months agoSon
7 months agoElinore
8 months agoDaron
8 months agoDierdre
7 months agoRicki
7 months agoShawnda
8 months agoStefania
8 months agoLino
8 months ago