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:
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:
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.
“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:
“example_data_name” is data name (see the example in picture 3).
See the Part 2 to get more answers to your questions.