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

How to implement templates in external pages

Discussion in 'XenForo Development Discussions' started by @Meigem, Jan 21, 2014.

  1. @Meigem

    @Meigem New Member

    A few days ago, we bought a XenForo license for our project and we have been exploring the code to try to understand how MVC works, but it's difficult.
    • We want to use the "register_form" template in an external page, generating the HTML code.
    • The question is: ¿How can we use the "register_form" template in an external page using the same HTML, CSS & PHP code? We only found the XML code in the XenForo folders, not the HTML.
    Thank you.

    P.D.: Sorry, we don't speak perfect english.
    seojoseph likes this.
  2. seojoseph

    seojoseph Member

  3. Vincent Gabriel

    Vincent Gabriel Active Member

    Not sure if this is what you are looking for but you can use the following to render a template:

    @Meigem and seojoseph like this.
  4. seojoseph

    seojoseph Member

    good job. :)
  5. @Meigem

    @Meigem New Member

    Thank you so much, Vincent! :)
    Vincent Gabriel likes this.
  6. Jeff Berry

    Jeff Berry Well-Known Member

            $this->_dependencies = new XenForo_Dependencies_Public();
            $this->_request      = new Zend_Controller_Request_Http();
            $this->_response     = new Zend_Controller_Response_Http();
            $this->renderer = $this->_dependencies->getViewRenderer($this->_response, 'Html', $this->_request);
            $content = $this->renderer->renderView('', $viewParams, 'xr_widget_' . $widgetId);
            return $content;
    This is what I use and it works fine.
  7. @Meigem

    @Meigem New Member

    One more question about your script, Vincent: How exactly works the function called renderTemplate()? I put 'register_form' in the first parameter, but I don't know what is array $params :S

    This is my code:
    $sdk = new XenForoSDK;

    $template $sdk->renderTemplate('register_form', array $params);
    Thank you for your help :)
  8. Vincent Gabriel

    Vincent Gabriel Active Member

    It's an array of params passed to the template. in the template mentioned above, under library/XenForo/ControllerPublic/Register.php

    $viewParams = array(
    'fields' => $fields,
    'errors' => $errors,

    'timeZones' => XenForo_Helper_TimeZone::getTimeZones(),
    'dobRequired' => $options->get('registrationSetup''requireDob'),

    'captcha' => XenForo_Captcha_Abstract::createDefault(),
    'tosUrl' => XenForo_Dependencies_Public::getTosUrl(),

    'regKey' => $regKey,

    'customFields' => $this->_getFieldModel()->prepareUserFields(
    $this->_getFieldModel()->getUserFields(array('registration' => true)),

    @Meigem likes this.
  9. @Meigem

    @Meigem New Member

    Thank you so much one more time Vincent :) This is what I wanted.

Share This Page