TL;DR:
I’m trying to add some stuff to the digest. I used to override the template, but can’t do that now, for reasons unclear.
Because overriding templates is bad, there are some places in the digest that get replaced with digest_custom_html
, but it inserts the text, so those need .html_safe
appended. At least one is in the wrong place (has “above” in the name, but is really below).
I think I have the skills for a PR on this one, unless, because it’s so simple, it might be easier for someone else to do it.
The Longer, more painful story.
I did it here: GitHub - pfaffman/discourse-add-to-summary: Add text to summary before and after title but that seems to have stopped working.
I think what I want to do, without changes to core, is override the digest.html.erb
template. I used to be able to do that by putting it in app/views/user_notifications/digest.html.erb
and that file would get processed instead of the one in core. That no longer seems to work.
Now, we do have some cool digest_custom_html
like this:
The clever reader will notice that popular topics starts up around line 78, long before line 277. I’m not sure how much time I lost thinking that nothing was happening because I was looking in the wrong place. But I digress.
I did manage to do this in plugin.rb
after_initialize.
require_dependency "user_notifications"
module ::UserNotificationsHelperOverride
def digest_custom_html(position_key)
puts "doing improved the digest: #{position_key}"
if position_key == "below_popular_topics"
puts "doing the custom html for above_popular_topics"
# Custom HTML for the popular topics position
"<div class='custom-popular-topics'>MY COOOOOOOL TEXT</div>"
else
puts "doing the super for #{position_key}"
super
end
end
end
And it is indeed adding text to the place I would expect it to be changed in the template!
Alas, it’s not treated as HTML, but as text. So. . . .
I looked in all_the_plugins and find no examples of anyone using this code.
Would it be a PR-welcome if I were to change the lines like
<%= digest_custom_html("below_popular_topics") %>
and replace them with
<%= digest_custom_html("below_popular_topics").html_safe %>
And, while I’m at it, maybe make sure that the names of the position_key
s are more similar to their position?