How do I DRY up common text in a Django template?
django, django-templates
Solution
Definitely use Inclusion Tags:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags
The tag file would either be something super simple like just the text "This is a static text" or the entire block:
{% if something %}
This is a static text
{% else %}
Something else happened
{% endif %}
"something" can be passed as a variable to the template tag so you can use that entire block in a variable way.
Problem
I have some static text that needs to show up at 2 locations within a template. For example: ``` <div> {% if something %} This is a static text {% else %} Something else happened {% endif %} </div> ... more html <span> {% if something %} This is a static text {% else %} Something else happend {% endif %} </span> ``` - I can do the above by duplicating the above text at 2 different locations in my template file(as shown above). - I could also create a model which will store the text(This is DRY but cost a call to the DB for a simple task) - I'm thinking of using `include template` but that's probably not the best way to achieve my goal. What's the best way to do it?