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