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

Discussion in 'XenForo Development Discussions' started by ragtek, Jan 22, 2011.

  1. ragtek

    ragtek Guest

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

    ATM i'm using:
     public static function getFooterTemplate() {
    $template = new XenForo_Template_Public('Foo', array());
    to return the template which i'm adding at an template hook and
       public static function showPhraseOptions(XenForo_View $view$fieldPrefix, array $preparedOption$canEdit) {
    $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?

  2. Mike

    Mike XenForo Developer Staff Member

    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.
    ragtek likes this.
  3. ragtek

    ragtek Guest

    ok perfect:)

    What's the default stuff?
    The user variables, page_container, etc.. or something different?
  4. Mike

    Mike XenForo Developer Staff Member

    Visitor, options, server stuff, etc. Easiest to look at $this->_defaultTemplateParams in the various Dependencies objects.

Share This Page