ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 12 - AD0-E720 discussion

Report
Export

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.)

A.
$block->getData('view_model')
Answers
A.
$block->getData('view_model')
B.
$block->viewModel()
Answers
B.
$block->viewModel()
C.
$block->getViewHodel()
Answers
C.
$block->getViewHodel()
D.
$block->getData('viewModel)
Answers
D.
$block->getData('viewModel)
Suggested answer: A, D

Explanation:

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''> ExampleObjectModel/ExampleObjectModel </referenceBlock>

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''> ExampleObjectModel/ExampleObjectModel </referenceBlock>

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.

asked 02/10/2024
samresh mahata
36 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first