Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#3888 closed (wontfix)

Allow {# comment #} tag to be multiline

Reported by: tonnzor Owned by: adrian
Component: Template system Version: master
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@…> 8 years ago.
Multiline comments

Download all attachments as: .zip

Change History (15)

comment:1 Changed 8 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 8 years ago by tonnzor <tonn81@…>

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 Changed 8 years ago by ubernostrum

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 follow-up: Changed 8 years ago by tonnzor <tonn81@…>

  • Resolution invalid deleted
  • Status changed from closed to reopened

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 Changed 8 years ago by Simon G. <dev@…>

  • Resolution set to wontfix
  • Status changed from reopened to closed
  • Summary changed from Template comments eats text to Allow {# 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.

Changed 8 years ago by tonnzor <tonn81@…>

Multiline comments

comment:6 Changed 8 years ago by tonnzor <tonn81@…>

  • Resolution wontfix deleted
  • Status changed from closed to reopened

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

comment:7 Changed 8 years ago by adrian

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

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

comment:8 in reply to: ↑ 4 Changed 8 years ago by SmileyChris

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 Changed 8 years ago by arthur@…

  • 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 Changed 8 years ago by ubernostrum

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

comment:11 Changed 8 years ago by anonymous

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 Changed 8 years ago by scum

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 Changed 5 years ago by Cerin

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 Changed 5 years ago by SmileyChris

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