Reputation: 2412
I have defined a custom template tag, in a file called custom_tags.py
:
from django.conf import settings
from django import template
register = template.Library()
@register.simple_tag
def currencysymbol():
if settings.LANGUAGE_CODE == 'en-gb':
return '£'
else:
return 'unknown'
Which is referenced in a template:
{% load custom_tags %}
{{ currencysymbol }}
The problem, is that it doesn't render. It is certainly loading the library, as I modified the load to tag to {% load foo %}
and it correctly told me that this library does not exist, and listed 'custom_tags' as one of the available options.
However, {{ currencysymbol }}
renders to nothing at all. To ensure that it wasn't my function, I modified it to simply return a string (without the if/else and the settings. stuff), but it still rendered nothing.
I believe that I have followed the docs, so I'm not sure what's happening. The page renders without errors, but my tag is simply not there.
Upvotes: 1
Views: 47
Reputation: 477684
You defined a tag, so that means you should use it like:
{% currencysymbol %}
So with the {% .. %}
brackets, not:
{{ currencysymbol }}
The {{ .. }}
is used for variables.
Upvotes: 1