Farrukh
Farrukh

Reputation: 131

Magento setTemplate at run time/programatically

I have static CMS pages on my website e.g. Privay Policy, Mony Back Gurantee etc. I have placed these links in footer of website from where these pages get opened with standard layout including header,footer and side bars..

I want to place these links as icons on my product pages but I do not want open them in new window. I prefer a fancybox/thickbox for this but I only want the page content to be shown and not header,footer, side bars etc to appear. In brief I want to set empty template for these CMS pages from only links which are on product page.

Can anyone let me know please that what is best way to achieve this?

Upvotes: 1

Views: 1337

Answers (2)

Ashish
Ashish

Reputation: 1

this is for cms pages only

go to mage/page/helper/layput.php

modify :-

public function applyHandle($pageLayout){     

    $pageLayout = $this->_getConfig()->getPageLayout($pageLayout);

    if(isset('emptylayout'))    {   
            $pageLayout->setCode('empty');
            $pageLayout->setTemplate('page/empty.phtml'); // this will work
            $pageLayout->setLayoutHandle('empty');

        }
            .
            .
            .

   }

//jquery code

 jQuery('.f-left li a').click(function(e){
            e.preventDefault();                         

            var url=jQuery(this).attr('href')+'?emptylayout'; 

            var data= '<iframe width="100%" height="550" frameborder="0" src="'+url+'"></iframe>';
            jQuery('#mask').html(data);
            jQuery.fancybox({
                    'href': '#mask',
                    'afterClose': function() {
                                        jQuery('#mask').html('');

                                        },
                  });

 });

Upvotes: 0

Alan Cole
Alan Cole

Reputation: 1695

You can use the 'Design' tab on the Edit CMS Page in the backend to 'overwride' a template to be used you can select the 'layout' from the drop down to be applied to only that page. There are two approaches for adding the new layouts, one is to build your own module that defines one something like in the layout xml for your module

<new_layout translate="label" module="page">
    <label>My New Layout</label>
    <block type="page/html" name="root" output="toHtml" template="page/new-layout.phtml">
</new_layout>

the other option is just to add this to the page.xml of in your templates layout file (and then a new-layout.phtml you want to use in templates folder) this might be a overkill for just editing a block from page to page but its the 'simplest' way.

All this code is untested and written from memory, but should be quite close to what you need.

Alan

Upvotes: 1

Related Questions