tags:

views:

76

answers:

3

How can lines in a template be outcommented or otherwise be disabled (short of deleting the line)?

E.g. if file "base_weblog.html" contains:

{% load ProgramVersion %}{% render_month_links %}

How can this line be hidden at runtime?

This does not work (e.g. TemplateSyntaxError if ProgramVersion is not a valid tag library - that is why I want to outcomment):

{% if false %}

{% load ProgramVersion %}{% render_month_links %}

{% endif %}

Update 1. This solves it:

{% comment %}

{% load ProgramVersion %}{% render_month_links %}

{% endcomment %}

Just curious: why is "load ProgramVersion" evaluated in the first case and not in the second? Is it too complicated to optimise for possibly nested control structures (and comments can not be nested)? Note that "if false" above should have been "if False", but it makes no difference. With a non-existing variable, say XYZ, load is still evaluated.

+4  A: 

Comments declared like this won't show up to users.

{% comment %} your comment text {% endcomment %}

Andrew Johnson
+6  A: 

Have you tried: {% comment %} .... {% endcomment %} ? Consult django template docs.

Grzegorz Oledzki
+1 for link to docs
Carl Meyer
+1  A: 

There is also a second option for comments. Nice for one-liners.

{# {% load ProgramVersion %}{% render_month_links %} #}
defrex