[ZPT] whitespace bug

Mark McEahern mark@mceahern.com
Thu, 21 Nov 2002 08:59:44 -0600


[Martijn Pieters]
> This is intended behaviour; whitespace surrounding a repeated tag is
> repeated as well. Otherwise there would be no way to preserve
> whitespace in between repeated items!

[Chris Withers]
> Why would you want to?

I'm mostly happy knowing that I can use the useless block trick--that solved
the particular problem we were having.  I don't have a firm understanding of
how and why TAL handles whitespace or what control I do have or should have
over that from a PageTemplate.  I would assume if you wanted to normalize
your HTML--nested tags indented just so, etc.--you probably wouldn't use
what PageTemplate renders without some tweaking?  That's not the problem we
had.  The problem we had was we didn't want whitespace between a bunch of
repeated spans.

Thanks for all the replies!

Just for reference, this TAL:

<!-- start TAL -->

<html>
  <head>
    <title tal:content="template/title">The title</title>
  </head>
  <body>

<p>No space before:

<span tal:repeat="n python:range(10)" tal:content="n"/>

<p>Four spaces before:

    <span tal:repeat="n python:range(10)" tal:content="n"/>

<p>Enclosed in a useless block:

<tal:block><span tal:repeat="n python:range(10)"
tal:content="n"/></tal:block>

  </body>
</html>

<!-- end TAL -->

Generates this output:

<!-- start output -->

<html>
  <head>
    <title></title>
  </head>
  <body>

<p>No space before:

<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span></p>

<p>Four spaces before:

    <span>0</span>
    <span>1</span>
    <span>2</span>
    <span>3</span>
    <span>4</span>
    <span>5</span>
    <span>6</span>
    <span>7</span>
    <span>8</span>
    <span>9</span></p>

<p>Enclosed in a useless block:

<!-- The following is all on one line, but will be wrapped by email -->
<span>0</span><span>1</span><span>2</span><span>3</span><span>4</span><span>
5</span><span>6</span><span>7</span><span>8</span><span>9</span></p>
<!-- The previous is all on one line, but will be wrapped by email -->

  </body>
</html>

<!-- end output -->

Cheers,

// mark

-