Named Template Reuse?

Tom Christian

Active member
I want to create several different SP dropdowns using a named template. Is it possible to only create one named template with the necessary code and then parse to it the necessary options/vaues from other SP's ?

Basically, I want to save time by using a single named template rather than creating a unique one for every single dropdown menu. Is this possible?
 
Check out this Admin Template:

style_property_unit_animationSpeedMultiplier

It is a style property named template and it is only used once.

But what you will see is how variables are used in various places, those variables grab values from the SP definition therefore it should allow the template to be reused.
 
Check out this Admin Template:

style_property_unit_animationSpeedMultiplier

It is a style property named template and it is only used once.

But what you will see is how variables are used in various places, those variables grab values from the SP definition therefore it should allow the template to be reused.

That seems like a fairly simple example - but what about for a more complex situation such as varying number of options for an HTML select menu?

What I don't understand is how I can define the select menu option/values inside the SP Definition and then access those with a loop or something inside the Named Template.
 
Yeah, for that, you would likely need a separate template for each different set of options.

You can include templates in templates, though; and you can also do foreach loops in the template. But the problem you will face, is that it isn't possible to build an array and pass it to another template.

You might be able to have a separate template for each SP, but include a template that contains common code, if that saves time.

Unfortunately, I think Style Properties are a little bit underpowered in this circumstance. Certainly what you want to do would be more likely to be possible with add-on options, but styles and add-ons are completely separate. e.g. You can assign options to add-ons and you can assign style properties to add-ons, but you can't assign options to styles.

That's where this suggestion comes in:
https://xenforo.com/community/threads/have-less-of-a-distinction-between-styles-and-add-ons.71196/

There's one more thought I'm having but I haven't actually had a chance to test it, yet.

You can include PHP in templates via the xen:callback tag. In theory, you could call the PHP from the template, pass some parameters to it, and return a different template or, e.g. a different array of options based on those parameters.

Certainly would work with public templates in some fashion, haven't ever tested it in Admin templates.
 
That's a shame. I'll just have multiple templates for now. Hopefully they'll consider your suggestion as it seems very strange to me also.

Thanks for the help.

Oh, one last question actually - IPB has a very simple way of returning the list of categories & forums (nodes) into a multi-select HTML element. This then outputs an array of node ID's for the selected options. Do you know if anything like this exists within XenForo. Presumably, it would need a named template and then some template code to output the node list. Is that possible?
 
Same story, unfortunately.

If you are creating an add-on, you can do this very easily with options using a PHP callback.

Also, it's worth noting, Style Properties can only save and output scalar values.
 
Same story, unfortunately.

If you are creating an add-on, you can do this very easily with options using a PHP callback.

Also, it's worth noting, Style Properties can only save and output scalar values.

The multi-select would be for an addon actually. Is there any documentation in regards to outputting the node list or perhaps an addon you know of that I can look at to see how it's done ?
 
Back
Top Bottom