1

for a plugin we generate an XML output which works on several systems without a problem. One system though adds extra content.

In the related controller we do have the following lines:

$this->getResponse()->setHeader('Content-Type', 'text/xml; charset=utf-8');
$somevars= array('protocol'=>$protocol,'server_name'=> $_SERVER['SERVER_NAME']);
$this->loadLayout()->getLayout()->getBlock('root')->setTemplate('foo/bar.xml.phtml')->setData('somevars',$somevars);

As said, this works on several systems but not on every system it seems. My question now is, what can we do to prevent magento from adding and/or rendering any other content except the content added via the above lines.

I tried unsetBlock, createClock, addBlock, but still seem to have some issues understanding the concept or the correct order.

Any help is appreciated.

2
  • What kind of extra content? Did you specify anything in layout XML for this controller? Commented May 2, 2016 at 20:59
  • Basically some div containers likely added by the template or another plugin. The site where this problem occurs is not created or maintained by me. Still I would like to make sure that our plugin can output the XML at any time without having to care for the template or plugins in a users Magento. Commented May 3, 2016 at 8:35

1 Answer 1

2

It seems like you only render one block and actually do not want to use anything from the default layout handle. In this case it's better to not load the layout from XML at all and instead only create this single block:

$block = Mage::app()->getLayout()
    ->createBlock('core/template')
    ->setTemplate('foo/bar.xml.phtml')->setData('somevars',$somevars);

$this->getResponse()->setBody($block->toHtml());

But it's still possible that there are extensions which manipulate any response with the controller_action_postdispatch event. To prevent this from being fired, you can set a flag:

$this->setFlag('', self::FLAG_NO_POST_DISPATCH);
1
  • Thanks, I will test it later today and flag your answer accordingly if this solves the problem for me. Commented May 4, 2016 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.