Opened 17 years ago

Closed 17 years ago

Last modified 5 years ago

#3888 closed (wontfix)

Allow {# comment #} tag to be multiline

Reported by: Artem Skoretskiy Owned by: Adrian Holovaty
Component: Template system Version: dev
Severity: Keywords:
Cc: arthur@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This template:

{{ "begin" }}{#
#} this text is never displayed
{{ "end" }}
#}()

Produces this output:

beginend

But it should produce this output:

begin this text is never displayed
end

Attachments (1)

multiline_comments.diff (771 bytes ) - added by tonnzor <tonn81@…> 17 years ago.
Multiline comments

Download all attachments as: .zip

Change History (15)

comment:1 by Chris Beaven, 17 years ago

Resolution: invalid
Status: newclosed

Actually, tags don't usually work over multiple lines so what you're trying to do is invalid.

If you actually want to output '{#', you should use the {% templatetag opencomment %} tag.

comment:2 by tonnzor <tonn81@…>, 17 years ago

OK, I see. However, there are some issues still:

Then:

  1. There is no notice about proper usage of {# #} in documentation - so everyone feels free to use it as he wants, with multiple lines too, that is invalid.
  2. Using multi-line comments seems useful feature, so why don't implement it?
  3. Text is eaten silently, without any notice from template system - that is very confusing.

comment:3 by James Bennett, 17 years ago

The difference is this:

{# This comment cannot span multiple lines #}

{% comment %}This
comment
can
span
as
far
as
it
want{% endcomment %}

So it's like the difference between // and /* */ in some languages -- one is a one-line comment, the other can span multiple lines.

The docs could make that more clear, I think.

comment:4 by tonnzor <tonn81@…>, 17 years ago

Resolution: invalid
Status: closedreopened

Yes, I see the difference. However, if it do not work, then it should do not touch original content at all.

I.e this template:

Hello
{# this
comment
has
newlines #} World! {{ "some more text" }}

Should produce this output:

Hello
{# this
comment
has
newlines #} World! some more text

But not this one (actual result):

Hello
some more text

Things must work or do not work, not "work sometimes" or "do not work and have some side effects".

Also I dont's see any reasons why {##} can't support newlines - if is much more easier to use them instead of {% comment %}{% endcomment %}

comment:5 by Simon G. <dev@…>, 17 years ago

Resolution: wontfix
Status: reopenedclosed
Summary: Template comments eats textAllow {# comment #} tag to be multiline

I have to agree with ubernostrum here - the functionality we already have is quite clear and supports single line and multi-line comments. Secondly, other template tags ( {{...}} ) don't go across line, whilst the blocks ({%...%}) do.

If you really feel that we're missing something, please raise this on django-developers and we can discuss it further.

by tonnzor <tonn81@…>, 17 years ago

Attachment: multiline_comments.diff added

Multiline comments

comment:6 by tonnzor <tonn81@…>, 17 years ago

Resolution: wontfix
Status: closedreopened

This feature is demanded - at least 4 people really want the fix - please see discussion Templates: short comments {##} eats text

comment:7 by Adrian Holovaty, 17 years ago

Resolution: wontfix
Status: reopenedclosed

Marking as wontfix, again, for the reasons pointed out in the thread you linked. Please don't reopen this ticket.

in reply to:  4 comment:8 by Chris Beaven, 17 years ago

Replying to tonnzor <tonn81@gmail.com>:

Yes, I see the difference. However, if it do not work, then it should do not touch original content at all.

New ticket regarding this incorrect behaviour: #4164

comment:9 by arthur@…, 17 years ago

Cc: arthur@… added

I just want to reply to this issue to say that we've been bitten by this problem too. We have a policy to always include a header in our files so we have something like this in our templates:

{#
 # NAME
 #    $HeadURL$
 # DESCRIPTION
 #    This template is used to foo the bar.
 # COPYRIGHT
 #    Copyright (C) 2007 Baz
 # VERSION ID
 #    $Id$
 #}

This code is accepted by the parser (no errors or exceptions). This however has the nasty side-effect of eating up all content upto the next tag. Using this (which we had before):

{% comment %}
# NAME
#    $HeadURL$
# DESCRIPTION
#    This template is used to foo the bar.
# COPYRIGHT
#    Copyright (C) 2007 Baz
# VERSION ID
#    $Id$
{% endcomment %}

causes weird problems with the {% extends %} tag (which must be the first tag).

Is there an acceptable way to include a standard documentation/copyright header?

comment:10 by James Bennett, 17 years ago

Use the comment/endcomment syntax if the comment must be multi-line, but place it after the extends tag.

comment:11 by anonymous, 17 years ago

It's a bit ugly though (does not place the copyright header above the code).

The real issue is that this was very hard to find since it worked in most cases (almost all our templates have a tag before content). Having an error message for both these cases (putting anything above extends and using multi-line tags) would be really helpful.

comment:12 by scum, 17 years ago

Another vote for allow {# #} multiline comments here. It's logical and allows for a quick way to quickly knock out a section of code for testing. I just wasted 15 minutes trying to figure out how to do multiline comments. That's gonna be a serious downer for future potential djangoers.

comment:13 by Chris Spencer, 14 years ago

I really wish the devs would re-consider their stance on this issue. No other templating language has such an unnecessarily verbose multi-line comment notation. Python allows multi-line comments with 6 characters (""""""), C with 4 (//), HTML with 7 (<!---->)). The fact that Django's is a whooping 29 characters ({% comment %}{% endcomment %}) seems quite unreasonable. If the logic for doing so is to maintain the logical consistency of the tag notation, then the tag notation is broken and should be fixed. Changing the single-line notation to support multiple lines would save a lot of unnecessary typing.

comment:14 by Chris Beaven, 14 years ago

Cerin, if you want discussion, take it to the django-dev google group please.

Note: See TracTickets for help on using tickets.
Back to Top