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

Named Template

Discussion in 'XenForo Development Discussions' started by Zephyr, Mar 15, 2013.

  1. Zephyr

    Zephyr Well-Known Member

    Hello, I would like to know what is the option below and how to use it please, when I use no field is created and there is no error.

    Thanks :)
  2. cclaerhout

    cclaerhout Well-Known Member

    If you select "spinbox", you can for example use these values in it:
    On any box, you should also be able to control its size:
  3. Zephyr

    Zephyr Well-Known Member

    Thank you, but it is mainly the format "Named Template" I do not understand.
  4. Bob

    Bob Well-Known Member

    its the name of an admin template

    Just edit some of the core xenforo options like "Contact URL" and you will see how its used.
    cclaerhout likes this.
  5. cclaerhout

    cclaerhout Well-Known Member

    Rendering a custom template directly from XenForo options
    As Bobster told you with "Named Template", this field will fetch the template you entered.

    So if you just need a new template with basic code in it (add a button, a simple field, etc...), the option "Named Template" is great.

    Rendering a pre-made template from Callback
    Remember in this thread this part of the code:
        public static function render_nodes(XenForo_View $view$fieldPrefix, array $preparedOption$canEdit)
    $preparedOption['formatParams'] = XenForo_Model::create('Sedo_ToggleME_Model_GetNodes')->getNodesOptions($preparedOption['option_value']);
    As you can see this PHP Callback willl also return a XenForo pre-made template (renderOptionTemplateInternal => the name of the function speaks for itself).

    Rendering a custom template from Callback
    If you need to manage many values (for example from the database) and still want to fetch your own template, you still need to use a callback.

    Here's an example (taken from the Button Manager):
              public static function render_bm_cust(XenForo_View $view$fieldPrefix, array $preparedOption$canEdit)
    $choices $preparedOption['option_value'];
    $editLink $view->createTemplateObject('option_list_option_editlink', array(
    'preparedOption' => $preparedOption,
    'canEditOptionDefinition' => $canEdit
    $configs XenForo_Model::create('KingK_BbCodeManager_Model_CustomButtons')->getAllConfig('strict');
    //Check if there is any custom configs
    if(!is_array($configs) || empty($configs))
    $configs['disable'] = array(
    'value' => 'disable',
    'phrase' => new XenForo_Phrase('Bbcm_no_custom_editor_available')
    $configs as &$config)
    $title 'button_manager_config_' $config['config_type'];
    $config['phrase'] = new XenForo_Phrase($title);
    $view->createTemplateObject('option_bbcm_bm_cust', array(
    'fieldPrefix' => $fieldPrefix,
    'listedFieldName' => $fieldPrefix '_listed[]',
    'preparedOption' => $preparedOption,
    'formatParams' => $preparedOption['formatParams'],
    'editLink' => $editLink,
    'choices' => $choices,
    'configs' => $configs,
    'nextCounter' => count($choices) + 1
    I don't know if this code is great, but the most important is that you can see that the command to fetch the template inside the callback is $view->createTemplateObject. Everything before is just some arrays and variables management. They are coming from the models, which are used to get datas from the database and must not mix with the above code. Check this comand:
    XenForo_Model::create('myClassPath)->myFunction('myOptionalArgument_1', 'myOptionalArgument_2');
    Bob likes this.
  6. pegasus

    pegasus Well-Known Member

    If you also want to add your own validation (especially if the input data-type won't match the type expected by DataWriter), since XenForo doesn't allow you to set callbacks in the StyleProperty definition (yet), you will also have to XFCP the XenForo_Model_StyleProperty::saveStylePropertiesInStyleFromInput method.

Share This Page