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

The subject block cannot be overwrite when inherit the email template. #28

Closed
sunshineo opened this issue May 7, 2013 · 5 comments
Closed

Comments

@sunshineo
Copy link

Is the subject block treated specially and did not get into the Django template inheritance process?
I had to use this work around that is put this in my base.email
{% block subject %}{{ subject }}{% endblock %}

And every time when call send email, the context need to have the subject line.

@BradWhittington
Copy link
Contributor

As a workaround in your base template use the following markup:

{% block subject %}{% block my_subject %}{% endblock %}{% endblock %}

And in your inherited templates:

{% block my_subject %}My subject!{% endblock %}

Due to the way the parser for django's templates works, it's a manual/deep voodoo to get the inheritence to work properly, and needs revisiting to handle this case more effectively...

@sunshineo
Copy link
Author

Thank you very much! I should have thought of this workaround. Could you put that in the document?

@awidgery
Copy link

Perfect - would be great to have this in the Readme - have just spend half an hour trying to make this work!

@awidgery
Copy link

There was a related issue where inheritance wasn't working quite right, when I had nested blocks.

I fixed it, and this original issue, by using block_render.py from here: https://github.com/uniphil/Django-Block-Render

I then replaced in vanilla_django.py the line (78):

response[part] = _get_node(multi_part, render_context, name=part)

with:

 response[part] = block_render.render_block_to_string(full_template_name, part, render_context).strip()

Worked like a charm for me - templates now render correctly with all inheritances.

That only changes the code for multipart emails - but that's all I'm using. A couple of extra lines would do it for HTML- or plain-only.

@BradWhittington
Copy link
Contributor

I'm closing this in favor of fixing inheritence using django-block-render in #29

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

3 participants