[Answered ]-Call another template tag which uses @register.inclusion_tag

2👍

I had a slightly different problem, and wanted to render a templatetag in my views, so I wrote a helper function that would allow me to do that. A variation of it should also work for rendering within a simple_tag. Here’s the helper:

def render_templatetag(request, tag_string, tag_file, dictionary=None):
    dictionary = dictionary or {}
    context_instance = RequestContext(request)
    context_instance.update(dictionary)
    t = Template("{%% load %s %%}{%% %s %%}" % (tag_file, tag_string))
    return t.render(context_instance)

It just creates a template on the fly that loads the proper tag file, and has the template_tag you’re using. For use in a simple_tag, you can modify the function and replace the request arg with context.

👤Eric

Leave a comment