Objective
- Replace the original Discourse template at
discourse/app/views/topics/show.rss.erb
. - Place a custom template in the plugin directory:
discourse-XXX/app/views/topics/show.rss.erb
. - Aim: Have RSS pages load the plugin template instead of the original template.
Attempted Approaches and Results
Approach 1: Directly placing the custom template in the plugin directory
- Action: Put the custom
show.rss.erb
intodiscourse-XXX/app/views/topics/
. - Result: The original template is still used; the RSS page does not load the plugin template.
Approach 2: after_initialize
with prepend_view_path
after_initialize do
class ::TopicsController
prepend_view_path File.expand_path("../app/views", __dir__)
end
end
- Result: The plugin template is ignored; the RSS page continues to use the original template.
Approach 3: after_initialize
with prepend_view_path
pointing to the plugin directory
after_initialize do
class ::TopicsController
prepend_view_path Rails.root.join("plugins/discourse-XXX-plugin-name/app/views")
end
end
- Result: The plugin template is still not used; the RSS page continues to render the original template.
Approach 4: Overriding the feed
method and explicitly rendering the plugin template
class ::TopicsController
prepend_view_path Rails.root.join("plugins/discourse-XXX/app/views")
alias_method :original_feed, :feed
def feed
raise Discourse::NotFound if !Post.exists?(topic_id: params[:topic_id])
begin
@topic_view = TopicView.new(params[:topic_id])
rescue Discourse::NotLoggedIn
raise Discourse::NotFound
rescue Discourse::InvalidAccess => ex
deleted =
guardian.can_see_topic?(ex.obj, false) ||
(!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj.deleted_at)
raise Discourse::NotFound.new(
nil,
check_permalinks: deleted,
original_path: ex.obj.relative_url,
)
end
@first_post = @topic_view.posts.first
discourse_expires_in 1.minute
response.headers["X-Robots-Tag"] = "noindex, nofollow"
render file: Rails.root.join("plugins/discourse-XXX/app/views/topics/show.rss.erb"), formats: [:rss]
end
end
- Result: The plugin template appears to be called, but visiting a topic’s
.rss
page results in anoops
error.
I hope this report clearly summarizes the attempts and the issues encountered. I would greatly appreciate any insights, suggestions, or solutions from the community to successfully replace the show.rss.erb
template. Thank you in advance for your help!