magento主题开发

magento主题开发: 如何查找一个block

日期:2016-09-07 阅读:1000

如何查找一个block

Separate the SEO links at the footer area - Instead of having the link items to be one list, isolate ‘Advanced Search’ to be in the header instead.


Which module and layout file assigns a content block to a page is sometimes a little harder to find at first, especially if that block appears on every page in the header or the footer. But you can make a calculated guess that the SEO links are likely controlled by the catalog or catalogsearch modules or you can see that they are part of the footer structural block and open up layout/page.xml and look through the list of children under the footer block in order to locate a block that calls the footer links - you will find <block name=“footer_links”>, which is what calls the SEO links. Now that you know that layout updates reference the SEO links via the name=“footer_links,” now you will do a search in all the xml files for <reference name=“footer_links”>. You will find references for the footer_links block in catalog.xml (which calls ”Site Map”), catalogsearch.xml (which calls ”Search Terms” and ”Advanced Search”) and contacts.xml (which calls ”Contact Us”).

从模块或layout file找一个block是比较困难的。但还是有些方法: 比如要查找seo links,可能在footer部分,那就去page.xml找下,发现了footer_links

-----------------------

案例:把advance search从footer移到header

1. Whatever method you use, once you have located the area of the individual SEO link items, you will now begin the steps to isolate ”Advanced Search” from the bunch and make it its own thing in the header.
2. Copy any files you will need to modify over to your custom theme.
3. First go to your copied page.xml and create a new block

<block type=“page/template_links” name=“header_links” as=“header_links” template=“page/template/links.phtml”/>
and nest it inside <block name=“header”>.

This makes the layout updates telling Magneto to expect this link in header.phtml.

4. In the case of the header.phtml file, Magento is hard-coded to look for that filename, so let’s just edit the template file directly in our custom theme for this example. Open your template/page/html/header.phtml, and type in
<?=$this->getChildHtml(‘header_links’)?>
where you want the link to reside.
5. Now go to catalogsearch.xml, and cut or comment out this code:

<action method=“addLink” translate=“label title” module=“catalogsearch”><label>Advanced Search</label><url helper=“catalogsearch/getAdvancedSearchUrl” /><title>Advanced Search</title></action>
from <reference name=“footer_links”>.

This will remove the link from the footer.

6. Still in catalogsearch.xml, create a new reference to the new header_links block and nest the cut out code inside it like so:

<reference name=“header_links”> <action method=“addLink” translate=“label title” module=“catalogsearch”><label>Advanced Search</label><url helper=“catalogsearch/getAdvancedSearchUrl” /><title>Advanced Search</title></action> </reference>


7. Reload the frontend store to see your changes. We now have Advanced search in the header instead of the footer.

-----------

 

 

<<点击返回