This works well BUT the user has to delete the template text before they can start typing their post.
This theme component enables you to display the topic template text as a placeholder (watermark) text instead of the editable text. You simply click on the box and start typing.
It can be set to display all Topic Templates as placeholders, or you can do it on a case-by-case basis by adding a [placeholder] indicator to the Topic Template.
Thanks to @merefield for refactoring the JQuery element to use the Ember framework and Discourse core.
Please note the updated version is only tested to work on Discourse versions from 2.4.1 If you are on an earlier version of discourse, please try the original version which has been tested in version 2.3.10
Original version repo: https://github.com/naidihr/discourse-topic-template-placeholders_original
PS development note. I had to do a JQuery hack to get this to work as a theme component. If it is possible to update the placeholder via the model - I would be grateful of you would let me know.
<script type="text/discourse-plugin" version="0.8">
api.modifyClass("model:composer", {
applyTopicTemplate() {
this._super(...arguments);
Ember.run.schedule("afterRender", () => {
// do your work here
});
}
});
</script>
This should allow you to add some custom logic when Discourse applies category topic templates.
That said, this type of way of writing stuff is a bit outdated. I would also recommend that you give this a read if you plan to spend a lot time on Discourse themes. It makes life much easier.
FYI this only works if you first go to the category and create a new topic. If you try to create a new topic from the latest page and then select a category from the dropdown the text doesn’t display.
That’s expected? That’s how Topic Template functionality normally works. The Topic Template won’t be considered in the latter case.
But yeah, imho, that could be improved in even vanilla Discourse without this TC to support your latter case. I have personally found it annoying that users are not presented with the Template if they go the second route.
This might be due to some other reason because it works here on Meta. if you go to /latest, open the composer and then select the marketplace category you get the template we have for that.
Hi Robert - I tested it after the merge and it was working - but it no longer is for me? This is with the override setting - not using the [placeholder]. Please can you check with your build as well?
Also on my original version - it did work the same if you started a new Topic from the latest page and then select the category.
Hi Robert, I merged that last PR and updated to the latest theme component version in but it is still showing the template text for default by me, even though I have “display all topic templates as placeholders” set. I am on Discourse 2.4.1. Any more thoughts?
That works, but it also doesn’t work at all if display all topic templates as placeholders is turned on, even if I’m in the category. Regretting volunteering for this now?
Great Robert. That last PR has fixed it. Also when starting a topic from the latest or category pages. All looking good now. Thank you for taking the time to look at this. Very neat solution _super job
Howdy folks! We love the idea of this theme component!
I just tried to install it on our discourse instance but I’m running into some trouble here.
It seems that when enabled on the theme, it breaks some of the styling already in the theme.
For example, the buttons at the user drop down:
become like this when enabled:
In addition to this, the placeholder doesn’t appear to work, both with 'Display all your Topic Templates as placeholders (watermark text)' enabled, and disabled.
It could be that our discourse instance is v2.3.10?
I’ve taken a look at the code here and can’t discern why our styling would be messy.
We rely on another team to manage and update our discourse instance & it’s a bit of a big task to get that done.
I’m hoping for a quick tip to potentially fix this, but, if it boils down to our discourse version that’s fine too!