Magento, add custom url. Xml or Php/Html -
example: within catalogsearch.xml, can found:
<reference name="footer_links"> <action method="addlink" translate="label title" module="catalogsearch" ifconfig="catalog/seo/search_terms"> <label>search terms</label> <url helper="catalogsearch/getsearchtermurl" /> <title>search terms</title> </action> <action method="addlink" translate="label title" module="catalogsearch"> <label>advanced search</label> <url helper="catalogsearch/getadvancedsearchurl" /> <title>advanced search</title> </action> </reference> it's clear. within "footer_links" block, code add 2 urls, search , advanced search links. now, question is: why should add these 2 links through xml layout file instead of adding them directly inside phtml template related footer?!
i think, if it's same, there no convenience prefer 1 method instead other one, editing phtml file.
there quite few blocks in magento act kind of 'containers' child blocks added other layout files. defined in page.xml layout file, case footer_links block:
<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/> as can see instantiates block class mage_page_block_template_links contains addlink() block method layout file calls in <action> tag.
defining these kinds of blocks gives great versatility in setting content added across multiple layout files. not keep block declarations separated different layout files relevant particular modules, can theme dependant allowing change layout entirely between themes.
also, if move away using blocks, doing extent working in template file, dependant on how block constructed , children has, can lose of benefits of caching block html.
so working in template file directly has 3 main drawbacks:
- you lose benefit of using theme specific layout handles
- template files not kept clean
- you can lose block caching benefits
i know when new magento working in template files can seem solution in situation this, discover more magento layout , how functions, begin see massive benefits of working within standards set framework - in case using layout files. if understand benefits of having top level container blocks such content, header , footer, same benefits apply footer_links block.
Comments
Post a Comment