Topic Template "Templates"

On one of my sites, we make significant use of topic templates. We use them as “forms”, particularly in our “support” category where we ask for basic information “what’s the problem”, “software version”, etc. Our support category has numerous subcategories, each corresponding to a product we support. Each subcategory, however, uses the same topic template. Currently, if we want to update the template we have to do so manually for every single subcategory. It would be nice if we could define Topic Templates elsewhere, something similar to the canned replies plugin comes to mind, where we can then reference a template in category settings. That way, we only need to make the change once, and all the categories are updated, instead of the current manual system.

11 Likes

I would love this too. We have the same issue in our 3 larger Q&A categories.

Is there any way to achieve that out of the box with discourse?

Bumping this cause it’d also be super great to have :slight_smile:

In the mean time I would strongly recommend using our API here. That way you define it once, then loop through the categories and update it. Can be a huge timesaver if you have 1 template that has to be applied to 30 categories.

I am not strongly against this, but I feel like adding this to core would add a fair amount of complexity.

1 Like

There’s another aspect to this that I think is understated, outside the API controllability.

In GitHub you can setup issue templates, eg what you see when you go here. It’d be great if this type of approach was available :slight_smile:

My goal is to have some common content across many category descriptions.

And so without knowing a better way, I would also vote for the the utility of this feature. Especially because Discourse is so powerful that it overlaps the functionality of a Wiki-like software, but templates would seem to be a key missing element for that user case.

@sam , would you mind elaborating on how to use the API for this? Let’s imagine that for 30 topics (which happen to be the description of the Category), in the first half of the text you have some category-specific content, but the second half should be a generic template text. We can imagine how this would look if this feature was supported, where the second half is just {{my_template}}.

With the scripted API approach, you’d loop through the topics and update them. But because there’s no magical template string (it’s already expanded), you’d have to match the “old” template text to replace it with the new text. This could be a pretty ugly regex. Is the right approach here as easy as using some hidden HTML markup, such as divs? Thanks.

You can place a hidden <div> in you content if you need to do this.

<div data-template='unique'>
I am unique content
</div>

<div data-template='common'>
I am common content
</div>
I am unique content
I am common content

Or you could use an HTML comment to denote where common starts and unique ends

2 Likes