danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
595 stars 158 forks source link

How to get a parent comment in the followup email template? #323

Closed jdbit closed 2 years ago

jdbit commented 2 years ago

Hi, is there a method to get a parent comment text (if a user replied to some comment) in the followup email notification template?

danirus commented 2 years ago

No, django-comments-xtd does not provide anything in particular. But you can implement a simple_tag like the following in your templatetags directory:

@register.simple_tag(takes_context=True)
def get_parent_comment(context):
    return XtdComment.objects.get(pk=context['comment'].parent_id)

And use it in the email_followup_comment.txt template:

{% load your_templatetags_module %}

[...]

{% if comment.parent_id != comment.pk %}
    --- Parent comment: ---
    {% get_parent_comment as parent %}
    {{ parent.comment }}
    ---
{% endif %}

That would make it.

jdbit commented 2 years ago

Thanks! I'll use the template tag then.