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

Named Template

Zephyr

Well-known member
#1
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 :)
 

cclaerhout

Well-known member
#2
If you select "spinbox", you can for example use these values in it:
Code:
max=50
min=25
step=10
On any box, you should also be able to control its size:
Code:
size=3
Etc...
 

cclaerhout

Well-known member
#5
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:
PHP:
    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']);
        return XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal('option_list_option_checkbox', $view, $fieldPrefix, $preparedOption, $canEdit);
    }
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):
PHP:
          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))
        {
            unset($configs);
                  $configs['disable'] = array(
                          'value' => 'disable',
                          'phrase' => new XenForo_Phrase('Bbcm_no_custom_editor_available')
                  );
        }
        else
        {
            foreach($configs as &$config)
            {
                if(isset($config['config_type']))
                {
                    $title = 'button_manager_config_' . $config['config_type'];
                    $config['phrase'] = new XenForo_Phrase($title);
                }
            }
        }
 
              return $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:
Code:
XenForo_Model::create('myClassPath)->myFunction('myOptionalArgument_1', 'myOptionalArgument_2');
 

pegasus

Well-known member
#6
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.