• 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

#1
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.
 
#3
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.
Not sure if this is what you are looking for but you can use the following to render a template:

http://xenforo.com/community/resources/xenforo-sdk.2790/
 

Jeff Berry

Well-known member
#6
Code:
        $this->_dependencies = new XenForo_Dependencies_Public();
        $this->_request      = new Zend_Controller_Request_Http();
        $this->_response     = new Zend_Controller_Response_Http();
        $this->_dependencies->preRenderView();
        $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
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:
PHP:
<?php
require_once('../foros/XenForoSDK.php');
$sdk = new XenForoSDK;

$template = $sdk->renderTemplate('register_form', array $params);
echo $template;
?>
Thank you for your help :)
 
#8
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:
PHP:
<?php
require_once('../foros/XenForoSDK.php');
$sdk = new XenForoSDK;

$template = $sdk->renderTemplate('register_form', array $params);
echo $template;
?>
Thank you for your help :)
It's an array of params passed to the template. in the template mentioned above, under library/XenForo/ControllerPublic/Register.php

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)),
                true,
                $customFieldValues,
                false
            )
        );

        return $this->responseView(
            'XenForo_ViewPublic_Register_Form',
            'register_form',
            $viewParams,
            $this->_getRegistrationContainerParams()
        );
 
#9
It's an array of params passed to the template. in the template mentioned above, under library/XenForo/ControllerPublic/Register.php

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)),
                true,
                $customFieldValues,
                false
            )
        );

        return $this->responseView(
            'XenForo_ViewPublic_Register_Form',
            'register_form',
            $viewParams,
            $this->_getRegistrationContainerParams()
        );
Thank you so much one more time Vincent :) This is what I wanted.