Creating a new template within an addon

rellek

Well-known member
Hi,

is there a possibility (and if so, how do I do it?) to have an addon create a new template? It needs to be linked to that addon so it will be removed on uninstall.

Let's assume a user adds something through the addon which at the end needs a template for itself. The addon should create a template then so the user can edit it.
However, I want to have it removed on uninstall, so it should be linked to that addon.

Is that possible and how?

Thanks
 
Are you taking about a way of programmatically creating new templates? A bit like how creation of a page node automatically creates an associated template?

Of do you just want to create a template that is distributed with an add on?

The latter is simple. With debug mode enabled just go to Appearance, Templates, and select the Master Style. Click create new template and assign it to your add on.

To do the other thing it is almost as simple as inserting a new row into the database so that a template is created.

Like I say, you should look at the existing code which creates page nodes because essentially that seems to do what you need so you should be able to learn a lot from that code.
 
Hi,

is there a possibility (and if so, how do I do it?) to have an addon create a new template? It needs to be linked to that addon so it will be removed on uninstall.

Let's assume a user adds something through the addon which at the end needs a template for itself. The addon should create a template then so the user can edit it.
However, I want to have it removed on uninstall, so it should be linked to that addon.

Is that possible and how?

Thanks
no.
If you associate the template with the addon, the "custom created" template will be removed while an addon upgrade.
See also http://xenforo.com/community/threads/customized-flag-for-templates-and-phrases.53989/
 
A workaround is, to create e.g. an template title prefix like "myaddontemplates_" and to remove them while the addon deinstallation process. (search for all addons with title myaddontemplates_* and use the datawriter to delete them)
 
@Chris Deeming
No, I need it to be created on purpose as it depends on what the user creates with the addon. So the addon must create that template, but not on install but while being installed.

@xf_phantom
Well that's a problem then...
How would I have to handle this? Is there a datawriter for creating and deleting templates? Because I guess, it's not as easy as INSERT INTO xf_template and you're done. :)
 
Create instance of XenForo_DataWriter_Template, use bulkSet() to set template data. In that data set addon_id to your add-on id, style_id to 0. Parse it using data writer's reparseTemplate() method and save using save().
 
Back
Top Bottom