Topic template should update when the post category is changed

AI-generated summary

The discussion addresses a bug where topic templates do not update when a user changes a post’s category. calmh notes that while the current behavior avoids overwriting manual edits, it leaves irrelevant templates in place when switching categories. They suggest logic to replace the template if the post matches the previous category’s template or if no edits have been made. eviltrout confirmed the issue has been resolved, ensuring that templates are swapped out when the category changes, provided the user hasn’t manually altered the template.

Continuing the discussion from Topic Templates:

I have a forum where a single category would benefit from a topic template - the “support” category, as may be typical. This is the most used category, so it’s the default when anyone hits the “new topic” button so they get the topic template in question.

The problem is that if they change their post category, the (now irrelevant) topic template doesn’t go away (i.e. change to the blank template that is the setting for that other category). Likewise if you change to another category that does have a topic template, you are still left with the old topic template.

I get that the current behavior is “only set the template if the post was blank” to avoid stomping on user changes. That makes sense. However, it seems the better behavior may be “set the template if the post is blank or matches the template of the category I’m deselecting”?

Or possibly, have a simple “dirty” flag for the post that is initially false. When the user makes any edit (keypress) in the editor, set it to true. When changing the post category, replace the contents with the topic template if the dirty flag is false.

1 Like

I’ve fixed it so that if you don’t change the template, it will be swapped out when you change the category:

https://github.com/discourse/discourse/commit/ca8046c7c3f3d22124a1bd8d34d81ddc6c32a9e2

5 Likes

This topic was automatically closed after 2 days. New replies are no longer allowed.