We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum


Thread tagged as: Problem

Extra blank source lines when using Perch blocks

Anyone worked out a way of getting rid of all the extra blank lines that appear in page source code, from a template with lots of <perch:block> pairs in it?

The page works fine, but each source code line generated from the content of my <perch:blocks> pair is spaced apart with around 9 blank lines. I guess it may be a bit OCD but I usually write quite tight source code and its offending me (LOL).

I don't really want to write a template with no spare lines in it, and with all the <perch:block> pairs concatenated, because its not that readable, but it may be the only way.

Graham Street

Graham Street 17 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Yes if removing the block pair leaves a blank line and you have a load of them that will happen.

As white space isn't an issue in HTML it's fairly low priority for us to spend a bunch of time on over and above things that actually make a real difference to the product, If you really don't like it you can do as you suggest.

Thanks Rachel.

For anyone reading this and wanting to reduce the number I've found that putting a closing </perch:block> tag on the same line as the next opening <perch:block ...> tag, the number of extra blank lines of source code can be substantially reduced. It makes a difference when you have large number of <perch:block> pairs in the template, and still leaves the template code readable.

Drew McLellan

Drew McLellan 2638 points
Perch Support

The other trick you can use is to add a template comment

<!--*   *-->

When we remove those, we expand them to encompass any surrounding whitespace.

Otherwise, we don't, because whitespace is sometimes significant. In inline blocks of CSS or JavaScript, or in code samples or in <pre> sections. Whitespace matters there. There are ways we could start parsing the content of the template to find when and where it's safe to remove whitespace, but those are intensive and would slow down the rendering of your page - for virtually no gain.

Perfect - thanks.