trying to get a template


Active member
I am trying to get a template from a stand alone file..

So far this is what I got..

I tried every combination to try to render it , but can't seen find a way to.

The template I am trying to get is "account_alerts_popup"

Last thing I tried was

XenForo_ViewPublic_Helper_Alert::getTemplates($view, $alertResults['alerts'], $alertResults['alertHandlers']);
But it has a problem with the $view object not being the correct one. This is tricky as you can't interact with the view object and controllers the same way you can from within, just wondering if there is a way?.
//Initializing XenForo
        $startTime = microtime(true);
        $xenforoRoot = str_replace("\\","/", (dirname(dirname(dirname(dirname(__FILE__))))));
        $roorDir = $xenforoRoot;

        // Setup XenForo's autoloader
        require_once($xenforoRoot . '/library/XenForo/Autoloader.php');
        XenForo_Autoloader::getInstance()->setupAutoloader($xenforoRoot . '/library');

        XenForo_Application::initialize($xenforoRoot . '/library', $roorDir);
        XenForo_Application::set('page_start_time', $startTime);

        // Not required if you are not using any of the preloaded data
        $dependencies = new XenForo_Dependencies_Public();

        //Start Session

[INDENT=1]$alertModel = XenForo_Model::create('XenForo_Model_Alert');[/INDENT]

        $alertResults = $alertModel->getAlertsForUser(

        $alertsUnread = array();
        $alertsRead = array();
        foreach ($alertResults['alerts'] AS $alertId => $alert) {
            if ($alert['unviewed']) {
                $alertsUnread[$alertId] = $alert;
            } else {
                $alertsRead[$alertId] = $alert;


Well-known member
For rendering a template, you need a "View Renderer" object appropriate for rendering a template in HTML form. You can grab a view renderer from the dependency object you created right after initializing the xf framework. A view renderer also has a dependency on a Request object and a Response object, so you'll need to create it as well.

# Rendering a template

$request = new Zend_Controller_Request_Http();
$response = new Zend_Controller_Response_Http();

$viewRenderer = $dependencies->getViewRenderer($response, 'Html', $request);

// Now that you have an html view renderer, you can use it to render any view/template

$viewParams = array(
	'var1' => 'Value 1',
	'var2' => 'Value 2',

$content = $viewRenderer->renderView('', $viewParams, 'helloworld_view');
echo $content;
Rendering the alerts popup...
$viewParams = array(
	'alertsUnread'  => $alertsUnread,
	'alertsRead'    => $alertsRead,
	'alertHandlers' => $alertResults['alertHandlers'],

$content = $viewRenderer->renderView(
	'XenForo_ViewPublic_Account_AlertsPopup', $viewParams, 'account_alerts_popup'
echo $content;