1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

trying to get a template

Discussion in 'XenForo Development Discussions' started by Ajaxboy, Feb 17, 2011.

  1. Ajaxboy

    Ajaxboy 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

    PHP:
    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?.
    PHP:


    //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');

            
    //die($xenforoRoot);
            
    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();
            
    $dependencies->preLoadData();

            
    //Start Session
            
    XenForo_Session::startPublicSession();


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

            
    $alertResults $alertModel->getAlertsForUser(
                
    $visitor['user_id'],
                
    XenForo_Model_Alert::FETCH_MODE_POPUP
            
    );

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

    Shadab 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.

    PHP:
    # Rendering a template

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

    $dependencies->preRenderView();
    $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...
    PHP:
    $viewParams = array(
        
    'alertsUnread'  => $alertsUnread,
        
    'alertsRead'    => $alertsRead,
        
    'alertHandlers' => $alertResults['alertHandlers'],
    );

    $content $viewRenderer->renderView(
        
    'XenForo_ViewPublic_Account_AlertsPopup'$viewParams'account_alerts_popup'
    );
    echo 
    $content;
     
    thedude, lamnx and Wuebit like this.

Share This Page