0

I have a contact form template (modal.phtml), which I want to add to all pages on my site, but I need to be able to position it precisely, so I want to insert into the relevant page templates using $this->getChildHtml('contacts-modal'), instead of inserting via layout xml. So in page/2columns-right.phtml, I want to use that call to insert the template stored in contacts/modal.phtml. The layout xml i have below is automatically inserting this template - how do i go about correcting this? Thanks for any pointers, and apologies if this is a very basic thing!

       <reference name="content">
            <block type="core/template" name="contacts-modal" as="contacts-modal" template="contacts/modal.phtml"/>
        </reference>
bsod99
  • 1,287
  • 6
  • 16
  • 32
  • Wouldn't be better if you include it in the footer and position it via javascript?...just saying – Marius Aug 09 '13 at 12:35

1 Answers1

1

If you want to insert the template with $this->getChildHtml('contacts-modal') you have to declare it in the layout xml, look into the class Mage_Core_Block_Abstract to see how getChildHtml works. If you want to add it to other pages that don't have 2columns-right as main template, you have to add the xml reference like you did with 2columns-right, or you can use inside the parent template echo $this->getLayout()->createBlock('core/template')->setTemplate('contacts/modal.phtml')

Emi
  • 1,018
  • 9
  • 13
  • Thanks for the reply Emi. I was hoping to use your last suggestion there, but calling this from 2columns-right.phtml, for example, throws: Recoverable Error: Object of class Mage_Core_Block_Template could not be converted to string – bsod99 Aug 09 '13 at 14:31
  • All I needed was to add ->toHtml() to the end of that call. Working perfectly now, thanks – bsod99 Aug 11 '13 at 12:20