I’m using a custom template tag which calls another one, depending on which hour it is.
@register.simple_tag(takes_context=True)
def my_custom_template_tag(context):
"""
"""
now = datetime.now()
# if the current hour:minute is less than
# the publication switch settings defined hour
if now.strftime('%H:%M') <= settings.PUBLICATION_SWITCH_TIME:
print now.strftime('%H:%M')
return my_other_template_tag(context)
else:
pass
@register.inclusion_tag('my_other_template_tag_template_path', takes_context=True)
def my_other_template_tag(context):
"""
"""
return {
'foo'
}
the problem is, my_custom_template_tag seems to ignore the called “my_other_template_tag” @inclusion_tag. Is there a way to achieve this, while keeping using the @inclusion_tag ??
Thanks!
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:
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.