Template engine

3 views
Skip to first unread message

Juanjo Conti

unread,
Jun 12, 2008, 5:57:33 PM6/12/08
to django...@googlegroups.com
Hi, I am using Django's template engine to produce rtf files and I
have noticed something: if the first line of my template is a {%load
... %} tag then the result has a withe like at the to of it. This is
not a problem in html, the common use of the tempalte engine, but is
fatal in a rtf file.

I write this because I think that this behaibour should bi fixed, am I right?

Anyway I have putted the load tag in the second line of my tempalte :)

Juanjo
--
Juanjo Conti

Jeff Anderson

unread,
Jun 12, 2008, 6:02:13 PM6/12/08
to django...@googlegroups.com
The way to fix this is to include the {% load ... %} tag on the same
line as something else.

I'm not familiar with the RTF format, but to eliminate the blank line at
the top of an html file, you would do this:

{% load ... %}<html>

instead of

{% load ... %}
<html>

Hopefully this helps!


Jeff Anderson

signature.asc

Norman Harman

unread,
Jun 13, 2008, 2:48:40 PM6/13/08
to django...@googlegroups.com


Template's white space handling is one of the few things that irks me
about Django. I hate having to make confusing formating, jamming stuff
all on the same line just to get white space correct.

I really wish it had some whitespace handling tools like Cheetah
http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000680000000000000000


The spaceless tag helps sometimes, but not for your situation.


--
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___________________________________________________________________________
You've got fun! Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

Arien

unread,
Jun 13, 2008, 3:58:17 PM6/13/08
to django...@googlegroups.com
On Fri, Jun 13, 2008 at 9:48 AM, Norman Harman <nha...@statesman.com> wrote:
> Template's white space handling is one of the few things that irks me
> about Django. I hate having to make confusing formating, jamming stuff
> all on the same line just to get white space correct.
>
> I really wish it had some whitespace handling tools like Cheetah
> http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000680000000000000000

Or Template Toolkit's:

http://template-toolkit.org/docs/manual/Syntax.html#section_Chomping_Whitespace


Arien

Russell Keith-Magee

unread,
Jun 13, 2008, 4:45:02 PM6/13/08
to django...@googlegroups.com

If there is a particular whitespace-eating behaviour that you would
like, you could always implement it yourself in a template tag. If you
think the template tag could be useful for others, you can share it on
djangosnippets.org, or open a ticket to have the tag considered for
inclusion in Django itself.

If what you're proposing can't be done in a template tag, we're always
open to suggestions on how to make Django better. Put down your ideas
in a ticket, and we'll consider it.

Yours,
Russ Magee %-)

titan...@gmail.com

unread,
Jun 13, 2008, 5:21:36 PM6/13/08
to Django users
Is this white-space behavior the case with all template tags? Is it
desirable for all template tags?

Maybe only tags that are common to be at the top of a template file
could have this enhancement to erase whitespace between them and the
next real tag in the template?

It seems to me that if certain template tags are going to be present
at the top of a template file, and it would help their ease of use to
have trailing whitespace removed then those tags should be treated a
little differently than other tags.

Just my $.02

On Jun 13, 11:45 am, "Russell Keith-Magee" <freakboy3...@gmail.com>
wrote:
> On Fri, Jun 13, 2008 at 11:58 PM, Arien <regex...@gmail.com> wrote:
>
> > On Fri, Jun 13, 2008 at 9:48 AM, Norman Harman <nhar...@statesman.com> wrote:
> >> Template's white space handling is one of the few things that irks me
> >> about Django.  I hate having to make confusing formating, jamming stuff
> >> all on the same line just to get white space correct.
>
> >> I really wish it had some whitespace handling tools like Cheetah
> >>http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html...
>
> > Or Template Toolkit's:
>
> >http://template-toolkit.org/docs/manual/Syntax.html#section_Chomping_...

Norman Harman

unread,
Jun 13, 2008, 5:43:28 PM6/13/08
to django...@googlegroups.com
Russell Keith-Magee wrote:
> If there is a particular whitespace-eating behaviour that you would
> like, you could always implement it yourself in a template tag. If you
> think the template tag could be useful for others, you can share it on
> djangosnippets.org, or open a ticket to have the tag considered for
> inclusion in Django itself.
>
> If what you're proposing can't be done in a template tag, we're always
> open to suggestions on how to make Django better. Put down your ideas
> in a ticket, and we'll consider it.

What I'm use to is less of particular tag and more of a change to how
all tags/templates work. In short, lines in templates that have only
tags should be "invisible" i.e. they should not be in the output of that
template.

If after doing tag processing a line(that had 1+ tags to begin with)
consists of nothing but whitespace then eliminate that line, including
it's new line.

line numbers for ref:
1: <foo>{% if bar %}bar{% endif %}
2: {% for i in list %}
3: i
4: {% if False %}</foo><foo>{% endif %}
5: {% endfor %}
6: </foo>

which now creates something like this when bar=False, list=[1,2]
1:<foo>
2:
3: 1
4:
3: 2
4:
5:
6:</foo>

instead outputs this
1:<foo>
3: 1
3: 2
6:</foo>


But this is a backwards incompatible change, a minor issue, and with
effort it's possible to work around this issue just not beautifully
(which contrasts with the rest of Django).

Other stuff is higher priority and the real problem with Django is
http://superjared.com/entry/real-problem-django/. I didn't mean to
sound complainy in previous post, if anyone took it that way.

Scott Moonen

unread,
Jun 13, 2008, 5:50:48 PM6/13/08
to django...@googlegroups.com
Would it be possible to borrow from the embedded ruby syntax and define something like this:

{{ variable.name -}}
{% tag param1,param2 -%}

If the '-' was present as part of the tag closure token, the template processor would eat the next 1-2 characters only if they were a CR or CR/LF.

Although I suppose this might cause problems for some tags that had begin/end pairs,

  -- Scott
--
http://scott.andstuff.org/ | http://truthadorned.org/
Reply all
Reply to author
Forward
0 new messages