-
Notifications
You must be signed in to change notification settings - Fork 0
Concepts
- Every page has a common structure which is defined through a layout XML Files.
- A Layout is a collection of blocks in a tree structure.
- Each layout is a list of instruction on how a page must render what it must render and which Block(s) should kick off the rendering process.
- So basically all section in the layout are called View.
- Each View has a BLOCK which is a php class and a TEMPLATE file which are tied to each other.
- Blocks are independent components which can have there own data model called within itself.
- This provides ultimate flexibility and re-usability of design.
Blocks are the main entity through which System renders the layout. Through the use of blocks, System differentiates various parts of layouts. Basically, there are two types of blocks.
Structural Blocks are the main outline of any front end layout. Typically, they contain the Header, Left, Right, Main, and Footer section of a layout.
Content Blocks are the actual blocks that reside inside the structural blocks to produce the final visual output. These blocks present the block-specific functionality via HTML. The Category List, Product List, Sub-category List, Product Tags, Homepage product sections, and so are are the content blocks inside structural block.
The root
block is the parent of all blocks.
\Layout\Core\Block
blocks use view files to render content. The view file name are set within setTemplate() with view paths.
View are just pieces of Template files complied in the \Layout\Core\Block
class . Therefore $block in a view refers to the block.
All output blocks are rendered, e.g. by calling toHtml()
, which in turn can choose to render their children.
\Layout\Core\Block\Text
and \Layout\Core\Block\List
blocks automatically render their content.
There are two events that are fired around block rendering that can be used to modify the block before and after rendering the HTML:
- block.to.html.before
- block.to.html.after
A child block will only be rendered automatically if it is of \Layout\Core\Block\List
otherwise the getChildHtml
method needs to be called.
Block instances can be accessed through the layout, e.g. loadLayout()->getLayout().
Block output is controlled by the _toHtml() function
-
<reference>
- edit a block
-
<block>
- define a block
-
<action>
- call method on a block
-
<update>
- include nodes from another handle.
A layout handle may contain the following elements:
block: This element is used to define a new block. This element is usually defined inside a reference element when we want to create a new block. The block element must have a name attribute, which is a unique identifier of the block in the layout and a type attribute, which defines the block class name. If the block is of type or subtype of \Layout\Core\Block
, it can also have the template attribute which defines the actual phtml template file to be used for rendering the block
reference: This element is used to link an already defined block in any layout XML. To add any child block to an existing block, to modify attributes of an existing block or to perform any action on an existing block, the reference element is used to link to the existing block. The reference element must have a name attribute which refers to the existing block’s name.
remove: This element is used to remove an existing block from the layout. The block to be removed is specified with the name attribute.
action: This element defines an action to be performed on the referenced or newly defined block. An action is simply a method of the block instance on which it is to be executed. The method attribute defines the method name in the block instance and all child elements of the action element are treated as parameters to the method. This element can be placed inside reference or block elements.
update: This element loads an existing layout handle into the current layout handle. It provides a kind of inheritance of layout handles. It must have the handle attribute, which defines the handle of the block to be included.