Issue #4 new

can't use translation strings as tag arguments

created an issue

current evaluation of variables prohibit use of Django's translations:

{% menu_item "/foo/" _("Foo") %}

I suggest to follow django's path and use template.Variable approach, first replace initialization of variables in __init__:

self.url = template.Variable(url)
self.text = template.Variable(text)
self.classes = template.Variable(classes) if classes else None

then in the render function, resolve those variables against context:

url = self.url.resolve(context)
text = self.text.resolve(context)
if self.classes:
    classes = self.classes.resolve(context)
    classes = u''

this will allow to use translations and variables in place of each argument, as well it will save us from parsing strings (check is there is " or ' as the first char).

Comments (3)

  1. Matthew Schinckel repo owner

    The example you provide goes against django's template tag syntax: function calls are generally not permitted in template tags.

    How is this type of thing done in other situations?

  2. Log in to comment