#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)
Change History (15)
comment:1 by , 18 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 18 years ago
OK, I see. However, there are some issues still:
Then:
- 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. - Using multi-line comments seems useful feature, so why don't implement it?
- Text is eaten silently, without any notice from template system - that is very confusing.
comment:3 by , 18 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.
follow-up: 8 comment:4 by , 18 years ago
Resolution: | invalid |
---|---|
Status: | closed → 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 by , 18 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
Summary: | Template comments eats text → 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.
comment:6 by , 18 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
This feature is demanded - at least 4 people really want the fix - please see discussion Templates: short comments {##} eats text
comment:7 by , 18 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
Marking as wontfix, again, for the reasons pointed out in the thread you linked. Please don't reopen this ticket.
comment:8 by , 18 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 , 18 years ago
Cc: | 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 , 18 years ago
Use the comment
/endcomment
syntax if the comment must be multi-line, but place it after the extends
tag.
comment:11 by , 18 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 , 18 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 , 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 , 14 years ago
Cerin, if you want discussion, take it to the django-dev google group please.
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.