Parse TemplateTag Variables Safely
Often times I want to be able to interchangeably pass either literal strings or context variables to a custom templatetag. This function first checks a string for the existence of surrounding quotes and uses the string inside. If the string didn't explicitly use quotes it checks to see if it can resolve the string as a context variable. As a fallback the function will simply return the full string. Example: {% get_latest_by_tag 'django' %} {% get_latest_by_tag object.tag %}
- templatetag