magento - Add block to all CMS Pages with certain URL Key -
i'm trying discover whether possible or not. have series of cms pages represent our library.
so url keys these pages like:
- library/
- library/top-ten
- library/five-questions
- library/faq
- etc...
the powers want add static block appear only on library cms pages. there way, in layout xml file, target pages contain keyword, along lines of
<default> .... </default> <library_*> <reference name="right"> <block goes here/> </reference> </library_*>
you may find this question useful understand cms page layouts. while can’t accomplish trying in way going exactly, here couple of options consider:
add layout xml each of cms pages in admin
this preferred solution since leverages out of box functionality, requiring less maintenance , no coding knowledge modify.
when editing cms page, go design tab:
here can change page template. select custom page template—that create static block inserted in right column—under layout, or add custom layout xml directly textfield:
admittedly, violate dry principle since on each relevant cms page, it’s not of violation , uses magento’s intended features.
create custom layout handle
similar example in question linked earlier, create simple extension adds new layout handles relevant cms pages. observer this:
class my_layouthandle_model_observer { public function addlibrarycmshandle(varien_event_observer $observer) { if ($observer->getaction()->getfullactionname() == 'cms_page_view') { $page = mage::getsingleton('cms/page'); if (substr($page->getidentifier(), 0, 7) == 'library') { /** @var $layout mage_core_model_layout */ $layout = $observer->getlayout(); $layout->getupdate()->addhandle('custom_handle_library_page'); } } } }
then target new handle this:
<custom_handle_library_page> <reference name="right"> <block goes here/> </reference> </custom_handle_library_page>
Comments
Post a Comment