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

createTemplateObject vs new XenForo_Template

R

ragtek

Guest
#1
What is the "clean" way, to create templates and use them in the code & at template hooks?

ATM i'm using:
PHP:
 public static function getFooterTemplate() {
        $template = new XenForo_Template_Public('Foo', array());
        return $template->render();
    }
to return the template which i'm adding at an template hook and
PHP:
   public static function showPhraseOptions(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit) {
        return $view->createTemplateObject('ragtek_Foo_Option', array(
            'preparedOption' => $preparedOption,
        ));
    }
to create a "option" for the acp options.

Is this ok, or should i use other classes / methods for this?

thx
 

Mike

XenForo developer
Staff member
#2
If you can guarantee the type of object you want, it doesn't strictly matter. Though IIRC, createTemplateObject registers all of the default stuff for you as well. You don't get that if you create it directly.
 
R

ragtek

Guest
#3
ok perfect:)


createTemplateObject registers all of the default stuff for you as well. You don't get that if you create it directly.
What's the default stuff?
The user variables, page_container, etc.. or something different?
 

Mike

XenForo developer
Staff member
#4
What's the default stuff?
The user variables, page_container, etc.. or something different?
Visitor, options, server stuff, etc. Easiest to look at $this->_defaultTemplateParams in the various Dependencies objects.