Alice wrote:
Is there a means to pass a template variable {{ user_id }} to a custom
template tag,
{% build_menu "user_id" %} ?
In fact you can treat anything after your tag name as you like, it's
just a string. But for such natural thing as treating it as a variable
Django will help. For this you have to omit quotes and then in your
template tag function do:
def do_build_menu(parser, token):
bits = token.contents.split()
return BuildMenuNode(parser.compile_filter(bits[0]))
compile_filter is needed to store the first parameter to later evaluate
it when actual context will be available:
class BuildMenuNode:
def __ini__(self, user_id_var):
self.user_id_var=user_id_var
def render(self,context):
user_id=self.user_id_var.resolve(context)
...