建站资讯

magento的layout xml是怎样工作中的

作者:admin 发布时间:2020-11-20

A prised of default layout and layout updates that are made up of easy-to-learn XML tags. With mands, you can modify/assign content block-structural block relationships and also control store-front functionalities such as loading and unloading of block-specific JavaScripts to a page.

layout文档是xml文档, 能够用于合理布局和操纵js是不是载入等。

XML tags 详细介绍:

HANDLES

Each Magento module has it is own layout file, for instance catalog.xml is a layout file for the catalog module  
and customer.xml is for the customer module. 每一个控制模块都是有一个合理布局的xml文档。 

Each file is further separated into handles. xml文档实际由handles构成。

The handles that are available are pre-defined in the Magento core and by any active extensions in your store. 
For the most part, each handle corresponds to a type of page within your Magento store, 
such as  catalog_category_default  and  catalog_product_view , 
but there are some handles that apply to all pages, such as the  default  handle, 
and some that apply within pages based on specific statuses, such as customer_logged_in and customer_logged_out .

有的handels是在网站特殊网页页面里事先设定了的。例如归类是 catalog_category_default 和商品显示信息网页页面便是 catalog_product_view ,有些是全部网页页面用到的,例如default,有些是某些网页页面用到到的,例如客户登陆网页页面。 


A handle can occur in multiple layout files and blocks can be assigned to that handle or overridden by each layout file. For example, most layout files may contain the default handle. When parsing the layout files, Magento first grabs the layout updates assigned in the default handle in each of the layout files, reading them in the order as assigned in app/etc/modules/Mage_All.xml. It then parses the page-specific layout handles, again looking in all of the layout files for that handle, and finalizes the building of a store page.

 

BLOCK 区块链
Magento determines the behavior and visual representation of each building block of a page via the block tag. We have already mentioned the two types of blocks Magento employs - structural blocks and content blocks. The best way to distinguish between the two is by examining the behavior assigned to each via the tag attributes. A structural block usually contains the attribute as, through which the application is municate with the designated area (using the getChildHtml method) in a template. You will notice many occurrences of this as attribute in the default layout, because by nature the default layout is one that builds the groundwork upon which the page-specific layouts can begin adding onto. For instance, in the default layout, there are structural blocks such as left, right, content and footer being introduced. Although these blocks can exist in normal layout updates, why not first set up urring structural blocks in the default layout first, and then start adding content on a per-page basisThe available attributes for block are:

type This is the identifier of the module class that defines the functionality of the block. This attribute must not be modified.
name This is the name by which other blocks can make reference to the block in which this attribute is assigned 


before (and) after These are two ways to position a content block within a structural block. before= - and after= - mands used to position the block accordingly at the very top or very bottom of a structural block.
template - This attribute determines the template that will represent the functionality of the block in which this attribute is assigned. For instance, if this attributes is assigned catalog/category/view.phtml , the application will load the app/design/frontend/template/catalog/category/view.phtml template file.

action action is used to control store-front functionalities such as loading or unloading of a JavaScript. A full list of action methods will e available, but in the mean time the best way to learn about the different action methods is by playing around with them in the currently available layout updates.
as This is the name by which a template calls the block in which this attribute is assigned. When you see the getChildHtml( block_name ) PHP method called from a template, it is referring to the block whose attribute as is assigned the name block_name . (i.e. The method ?=$this- getChildHtml( header )? in the a skeleton template correlates to block as= header ).  - as 表明分派给某一区块链,能够用getChildHtml来启用。

REFERENCE 引入
reference is used to make reference to another block. By making a reference to another block, the updates inside reference will apply to the block to which it correlates (以下图).
To make the reference, you must target the reference to a block by using the name attribute. This attribute targets the block tag s name attribute. Therefore, if you were to make a reference by reference name= right , you are targeting the block named block name= right .


收缩