Code

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#648 closed defect (fixed)

[patch] Add a comment tag like {# commented #}

Reported by: hegemon Owned by: adrian
Component: Template system Version:
Severity: minor Keywords:
Cc: mccutchen@…, gary.wilson@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The default {% comment %} {% endcomment %} block is too much writing.

Attachments (2)

comment_tag.diff (2.3 KB) - added by Hawkeye 8 years ago.
Patch to implement {# #} style comments
comment_syntax_with_tests.diff (3.6 KB) - added by mccutchen@… 8 years ago.
New patch, including tests, against r3754

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by adrian

  • Resolution set to wontfix
  • Status changed from new to closed

Two different types of syntax -- {% %} and {{ }} -- is already more than enough for our template system. We shall not go down a Perlish path! :)

comment:2 Changed 8 years ago by django@…

I think a {# balbalbla #} would be much nicer for comments then the unreadable and blowisch comment tag.
With those 3 types everything would be covered. With the current syntax for comments, i hardly doubt that people make comments at all, and if so, they are hard to read.

comment:3 Changed 8 years ago by adrian

  • Summary changed from Add a comment tag like {%# >>commented {{ code }}<< %} to Add a comment tag like {# commented #}
  • Type set to defect

comment:4 Changed 8 years ago by Hawkeye

  • Summary changed from Add a comment tag like {# commented #} to [patch] Add a comment tag like {# commented #}

I think that this is a valuable proposal...

It will make code much more readable, and will encourage the use of comments...

{% if somecondition %}
foo
{% else %}{% comment %}not somecondition{% endcomment %}
bar
{% endif %}

is not readable, and I don't think it seems Django-ish... it's inelegant.

{% if somecondition %}
foo
{% else %} {# not somecondition #}
bar
{% endif %}

is much more readable

I'm uploading a patch for consideration.

Changed 8 years ago by Hawkeye

Patch to implement {# #} style comments

comment:5 Changed 8 years ago by mccutchen@…

  • Cc mccutchen@… added

I'm attaching a new diff that adds tests to the previous diff. This one was made from the root of django_src instead of from the django_src/tests/regressiontests/templates directory, it may be easier to apply.

I really think better comment syntax would be a boon to Django's template system.

Changed 8 years ago by mccutchen@…

New patch, including tests, against r3754

comment:6 Changed 8 years ago by SmileyChris

See related ticket to allow block tags to be commented out: #2721

comment:7 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Cc gary.wilson@… added

I'm a fan of {# #} also.

comment:8 Changed 8 years ago by django@…

I'm totally fan of this (even implemented it half way on my sendbox, but forgott about it).
I think this patch increases the usage of comments a log, currenty, I rarly comment anything, because it makes the template even less readable. This is very problematic for complex templates. for example, i have some templates that generate .DOT and kml files, and have to make calculations to generate some values (no, the calculation is on the right place here, because i generates colors, length, etc out of numeric values). doing such things are very ugly in templates and hard to read anyways, without comments, outsiders can't do changes due a lack of understanding, at least they told me so :)

comment:9 Changed 8 years ago by adrian

  • Resolution changed from wontfix to fixed

(In [3931]) Fixed #648 -- Added comment syntax to template system: {# #}. Thanks for the patch, mccutchen@… and Hawkeye

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.