Mark_Wass tried to follow a guide to display full names in comments embeds, but the changes didn’t take effect after rebuilding the app. Canapin explained that rebuilding the app overwrites changes made inside the container, and suggested using a theme component or plugin to customize Discourse.
Mark_Wass created a plugin, but was having trouble getting it to work. Canapin pointed to an example plugin that targets the same file. Mark_Wass was able to get the plugin working by fixing a path issue and using a private GitHub repository.
The final solution involved adding the custom template to a custom_views folder and using the after_initialize method to prepend the view path. The working plugin code is:
after_initialize do
::EmbedController.prepend_view_path File.expand_path("../custom_views", __FILE__)
end
Additionally, to use a private GitHub repository, Mark_Wass found that the app.yml file should include the GitHub username and token in the cloned URL:
cd /var/discourse
./launcher enter app
x86_64 arch detected.
root@discourse-app:/var/www/discourse# cd app/views/embed/
root@discourse-app:/var/www/discourse/app/views/embed# nano comments.html.erb
Nano was not installed so I installed it and edited comments.html.erb replacing the lines mentioned in the referred post.
I then exited the launcher and ran
./launcher rebuild app
After the rebuild it did not make any difference, I still see usernames instead of Full Names in the embeds.
But I don’t seem to be seeing the changes I’m expecting in embeds. I’ve added a couple of custom css class names and I’ve changed <%= post.user.username %> to <%= post.user.name %>. Would appreciate some more nudging in the right direction to get this working. I can’t imagine it’s too complicated to override a plugin template file from another plugin.
What I have been able to do is enter the app and manually copy my plugins version of the template over to /var/www/discourse/app/views/embed/ then I restart the app and I see the results I’m looking for.
I just need to have the auto-magically happen when the plugin is loaded, and that’s where I’m stuck.
@Canapin Yes! Got it all working. Here is what the plugin.rb ended up looking like. Turned out I just had a path issue where I was putting the custom version of the file.
I ended up putting it in a folder /custom_views/embed/comments.html.erb
# frozen_string_literal: true
# name: optuma_discourse_custom_embed
# about: A simple plugin to used to customise the template in the forum embeds
# version: 1.0.0
# authors: Optuma Pty Ltd
# url: https://github.com/OptDev/optuma-discourse-custom-embed
# required_version: 2.7.0
after_initialize do
::EmbedController.prepend_view_path File.expand_path("../custom_views", __FILE__)
end