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

Access context from filter #267

Open
globizcorp opened this issue Jun 22, 2021 · 1 comment
Open

Access context from filter #267

globizcorp opened this issue Jun 22, 2021 · 1 comment

Comments

@globizcorp
Copy link

It would be a good feature if we could access the context from a filter and use some global variables here, like the selected language, using of preview mode, etc.

For example, consider the following email template:

<tr>
	<td><b>{{'mail_order_id'|lang:ln}}</b></td>
	<td>{{order.Id}}</td>
</tr>
<tr>
	<td><b>{{'mail_order_name'|lang:ln}}</b></td>
	<td>{{order.Name}}</td>
</tr>

Here we have a custom filter, which can translate the corresponding strings. But we have to pass the ln param to every filter, because the filter itself doesn't know the actual language, however it has been set in the context (context["ln"] = "en").

Another example is an embedded image: <img src="{{'spacer.gif'|images:preview}}"/>
Here the filter replaces the src to a full URL (in preview mode) or to a cid:xxxx embed mark. Another issue here is that we need to store somehow which images we should include later, when sending the actual mail, so we can embed them. Now we have to rescan the template file, looking for src attribs and css backgrounds, and get the images from here, however the images filter could do that for us and store the image list on the context itself. Later we can easily grab the info from here.

Thanks for your great work!

@xc
Copy link

xc commented Nov 11, 2022

Support this. Without context the filter misses lots of state/context.

In my case I had to switch to function to use context but filter is semantically correct because it's about output.

My case: #200 (comment)

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

No branches or pull requests

3 participants