Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No subscription / user context variable available in template for Personalization #368

Open
mrxsal opened this issue Apr 9, 2021 · 1 comment

Comments

@mrxsal
Copy link

mrxsal commented Apr 9, 2021

(beginner django developer here)
It seems to me there is no subscription context variable available in the message.html template.
image
(screenshot is from django-debug-toolbar)

How would one go about with email personalization?
something like: Hi {{ user.first_name }} or, Hi {{ subscription.email }}.

I would expect the subscription context variable to be available to use as a standard.

Related Question : How would I be able to add my own custom context variables to this? I see that I am not able to to use my own custom context processors in the template, such as {{ user }}
Say I own airbnb.com and I want to show 5 recommended Listings. How could I include a "Listing" context variable?

Sorry if this is not the place to ask these questions.

@mrxsal
Copy link
Author

mrxsal commented Apr 16, 2021

Forgive me for the noobiness.
I realize that the subscription instance is added to the template's context in the Submission model when send_message() is run.
That being said, I would appreciate some help understanding how I can add my own context variables to this.
In the send_message method sits the "variable dict", which I hope to append my own context variables to.
I don't know if this is the right way to go, but I'm trying monkey-patching. I can't seem to be able to access the "variable dict" unless I add it directly in the source code.

DJANGO_NEWSLETTER_CONTEXT_PATCH = True  # adds context to Submission


def monkey_patch():
    if DJANGO_NEWSLETTER_CONTEXT_PATCH:
        from newsletter.models import Submission
        old_send_message = Submission.send_message

        def new_send_message(self, *k, **kw):
            old_send_message(self, *k, **kw)
            # old_send_message.variable_dict['test'] = 'testvalue'  # add more context here (gives error)

        Submission.send_message = new_send_message

Can you give me some pointers to solve this? it's really appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant