Return content without pagecontainer

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
Is there a way to return ONLY the "template content" without the page_container?

I'm aware that i could create a empty template with
Code:
{xen:raw $contents}
and use the containerTemplate variable, but that's IMO a little bit ugly and unnecessary...
I would need this for 3 addons and i don't want to create the same "unnecessary" template in 3 addons


if you don't know what i mean:

my template "foo":

Code:
<p>foooo</p>


if i use now
return $this->responseView('', 'foo');

it will return the xenforo container with foo text.
but i want to return ONLY <p>foo</p> but as normal html page and not as json response
 
This was a fun one...

What you want is to use XenForo_ViewRenderer_Raw which does not use a container. However, this ViewRenderer does not render a content template. Rather it uses output directly from your View (e.g. ViewPublic) using renderRaw(). So you need to render your content in your View. Here is an outline I have come up with:

1) Set the "raw" response type in your route:

Rich (BB code):
<?php

class YourAddon_Route_Prefix_You implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		$match = $router->getRouteMatch('YourAddon_ControllerPublic_You', 'index');
		$match->setResponseType('raw');
		return $match;
	}
}

Or in your controller. For example:

Rich (BB code):
<?php

class YourAddon_ControllerPublic_You extends XenForo_ControllerPublic_Abstract
{
	public function actionIndex()
	{
		...

		$this->_routeMatch->setResponseType('raw');
		return $this->responseView('YourAddon_ViewPublic_You', 'content_template', $params);
	}
}

2) Then add a renderRaw() function to your View that renders the template:

Rich (BB code):
<?php

class YourAddon_ViewPublic_You extends XenForo_ViewPublic_Base
{
	public function renderRaw()
	{
		return $this->createTemplateObject($this->_templateName, $this->_params);
	}
}
 
2) Then add a renderRaw() function to your View that renders the template:

Rich (BB code):
<?php
 
class YourAddon_ViewPublic_You extends XenForo_ViewPublic_Base
{
public function renderRaw()
 {
 return $this->createTemplateObject($this->_templateName, $this->_params);
 }
}
thx
the view object was missing
 
Top Bottom