AD0-E717 practice question 14 of 15
What is the correct way to inject CMS block in a layout?
Full set: 77 questionsThe correct method to inject a CMS block into a layout file is by declaring a block of class Magento\Cms\Block\Block and passing the unique block identifier as an argument. The node is the standard Magento 2 practice for passing data to a block's constructor from layout XML. The blockid argument name corresponds to the data key the Magento\Cms\Block\Block class uses to load the appropriate CMS block content from the database. This approach is declarative and aligns with modern Magento 2 development principles.
B. The tag is a deprecated method for calling public methods on a block instance. While it might work, it is not the recommended or correct modern approach; should be used for constructor injection.
C. Using a direct attribute like identifier="mycmsblockidentifier" in the tag is not a valid Magento 2 layout XML syntax. Block data must be passed via the sub-node.
1. Adobe Commerce Developer Guide, Layout XML instructions, Block arguments: This official documentation explicitly shows the use of the node to pass data to a block. It states, "Arguments are set for a block using the sub-node... The argument name corresponds to the parameter name in the constructor." This validates the structure used in option A.
Source: Adobe Commerce Developer Documentation > Frontend Developer Guide > Layouts > Layout XML instructions > Block arguments.
2. Adobe Commerce Developer Guide, Layout XML instructions, Common layout instructions: This section provides a direct example of how to add a CMS (static) block to a layout, which perfectly matches the syntax in option A.
Example Snippet: exampleblock
Source: Adobe Commerce Developer Documentation > Frontend Developer Guide > Layouts > Layout XML instructions > Common layout instructions.
3. Adobe Commerce Developer Guide, Layout XML instructions, Action: The documentation notes the deprecation of the tag for setting block properties. It explicitly recommends using the node instead, confirming that option B is not the correct or preferred method.
Source: Adobe Commerce Developer Documentation > Frontend Developer Guide > Layouts > Layout XML instructions > Action.
Keep practicing
Take the free AD0-E717 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other AD0-E717 practice questions
- Question 1A developer is creating a class \Vendor\Module\Model\MyModeL How should that class be def…
- Question 2What is one purpose of a customer data JS library?
- Question 3What folder would a developer place a custom patch on an Adobe Commerce Cloud project to …
- Question 4What action can be performed from the Cloud Project Portal (Onboarding Ul) of an Adobe Co…
- Question 5What database engine is part of the infrastructure of Adobe Commerce Cloud projects?
- Question 6What is the default store ID for the admin panel?
