Question

I have an issue. I've written a custom template tag with a function signature like this-

def has_paid_for_article(article, request):

Now, in my template tag I have a conditional statement to determine whether a user can download an article or not (this is determined by if the article is older than two years or the logged in user has paid for the article). Here's the snippet-

{% if article|is_older_than_two_years %}
<span class="amp">&amp; </span>{% get_article_download_link article  %}
{% else %}
download
{% endif %}

The aforementioned snippet works fine, however I need to call the has_paid_for_article() function inside of a conditional statement. I've tried the following ways to make this happen-

 {% if article|is_older_than_two_years or article|request|has_paid_for_article %}

,

 {% if article|is_older_than_two_years or [article, request]|has_paid_for_article %}

This one works outside of the conditional statement-

{% if article|is_older_than_two_years or has_paid_for_article article request %} 

What would be the correct syntax here? Also, I've read other posts on the topic, I CANNOT put this logic in the view. I won't go into detail, but with the way it works, that is not an option. Thank you!

Était-ce utile?

La solution

Try

{% if article|is_older_than_two_years or article|has_paid_for_article:request %}

See Writing custom template filters

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top