Get Free Audit

Effectively Use the Magento Block‐Template Design System

Jun 21, 2017

1314 Sergey Samets

Effectively Use the Magento Block‐Template Design System

How can a child block be displayed?
In case you’re going to get “child block” displayed, you should call PHP. You can see the example of such a call:

Effectively Use the Magento Block‐Template Design System

The value within quotes (“category.subcategories” is used in the example) should coincide with the attributes “as” or “name” belonging to the child block that we want to show here. Let’s remember if the attribute “as” isn’t assigned, it is automatically equal to the attribute “name”. Please, note that if we do not enter any value within quotes, all child blocks for this parent block will be shown.

How to access data from a parent block?
In order to access data from a parent block, we can use the variable “$this”. For this variable PHP method for applying to, a parent block should be used. The example is shown below:

Effectively Use the Magento Block‐Template Design System

Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey

In the example mentioned above, in the variable “searchCount” we write data from the closest parent block. If the block has several parent blocks and we need to apply not to the closest one, but to the required one, the attributes “as” or “name” of the required parent block should be defined within brackets “getParentBlock()”. Besides, the attributes should be written in quotes.

How can data be set on a block via layout XML?
In order to set data on a block via layout XML, we should go to the file local.xml and apply the method “setData”. For more details, see the picture 3.

Effectively Use the Magento Block‐Template Design System

“example_block” is the name of the block for which data is added.
“example_data_name” and “example_data_value” are data parameters (name and value).

To display the data in a block template, we should apply the method “getData”. The result you can see in the picture:

Effectively Use the Magento Block‐Template Design System

“example_data_name” is data name (see the example in picture 3).

See the Part 2 to get more answers to your questions.

Magento 2 Development

Take your online store to the next level with BelVG Magento 2 Development

Visit the page
Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *