Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-04-18 14:53:18

stellaris
Member
Registered: 2008-03-06
Posts: 19

[solved] Conditionals generate lots of whitespace in markup?

Hi,

I am relatively new to Textpattern (4.0.6) and noticed that the use of conditionals seems to generate a lot of whitespace around the output in the markup. I output different title tags in the <head> part of my xhtml template depending on what section is currently displayed.

What is causing the whitespace to be generated and is there a way to have the whitespace removed?

Looking forward to your advice.

Last edited by stellaris (2008-04-18 17:56:10)

Offline

#2 2008-04-18 15:39:57

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: [solved] Conditionals generate lots of whitespace in markup?

Can you give an example of how the TXP tags look in your template and what the resulting HTML code is?

Offline

#3 2008-04-18 16:24:18

stellaris
Member
Registered: 2008-03-06
Posts: 19

Re: [solved] Conditionals generate lots of whitespace in markup?

Hi,

the dev computer is at work, so will show you the resulting markup from there on Monday. I can show you though how I tried putting the conditionals:

<txp:if_section name="about">
  <title>About us &mdash; Sitename</title>
</txp:if_section>
<txp:if_section name="about"><title>>About us &mdash; Sitename</title></txp:if_section>

Both variants produce lots of whitespace (5+ lines above and below) around the output <title> tag.

Offline

#4 2008-04-18 16:29:13

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [solved] Conditionals generate lots of whitespace in markup?

<txp:if_section name="about"><title>About us &mdash; Sitename</title></txp:if_section>

You probably have more lines like this, separated by line breaks. You would have to remove all line breaks to get rid of the whitespace, but it will make your code less readable. It’s a choice ;)

Offline

#5 2008-04-18 16:34:41

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: [solved] Conditionals generate lots of whitespace in markup?

What happens if you do this… where are the empty lines inserted?:

111<txp:if_section name="about">222<title>About us &mdash; Sitename</title>333</txp:if_section>444

Offline

#6 2008-04-18 17:27:31

stellaris
Member
Registered: 2008-03-06
Posts: 19

Re: [solved] Conditionals generate lots of whitespace in markup?

Alright,

I think can confirm that the whitespace is indeed output by non-matching conditionals in this case.

<txp:if_section name="about"><title>About us &mdash; Sitename</title></txp:if_section>
<txp:if_section name="articles"><title>Articles &mdash; Sitename</title></txp:if_section>
<txp:if_section name="stellenanzeigen"><title>Stellenanzeigen &mdash; Sitename</title></txp:if_section>

I have 3 conditionals for the <title> tag set up here at home now, of which the last one matches in the test section “stellenanzeigen”. The generated empty lines seem to be where the other non-matching conditionals were in the template.

111<txp:if_section name="about">222<title>About us &mdash; Sitename</title>333</txp:if_section>444

does not generate whitespace, but prints the numbers and the <title> tag on a match. If I mimick my setup from above with 3 conditionals, the non-matching conditionals output 111444 each. So I end up with 3 lines again, only filled with stuff.

Last edited by stellaris (2008-04-18 17:28:09)

Offline

#7 2008-04-18 17:33:06

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [solved] Conditionals generate lots of whitespace in markup?

What happens if you move the line breaks to inside the conditionals?

<txp:if_section name="about">
<title>About us &mdash; Sitename</title></txp:if_section><txp:if_section name="articles">
<title>Articles &mdash; Sitename</title></txp:if_section><txp:if_section name="stellenanzeigen">
<title>Stellenanzeigen &mdash; itename</title></txp:if_section>

or

<txp:if_section name="about"><title>About us &mdash; Sitename</title>
</txp:if_section><txp:if_section name="articles"><title>Articles &mdash; Sitename</title>
</txp:if_section><txp:if_section name="stellenanzeigen"><title>Stellenanzeigen &mdash; itename</title>
</txp:if_section>

Last edited by els (2008-04-18 17:35:12)

Offline

#8 2008-04-18 17:43:48

stellaris
Member
Registered: 2008-03-06
Posts: 19

Re: [solved] Conditionals generate lots of whitespace in markup?

Uh,

putting the conditionals directly one after the other did the trick. I am pretty sure I already tried that after getting a reply in the German section this afternoon,hmmm. Anyway, thanks! :)

Last edited by stellaris (2008-04-18 17:45:22)

Offline

#9 2008-04-18 17:46:43

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [solved] Conditionals generate lots of whitespace in markup?

Yes, usually not matching conditional tags outputs whitespace, but I think they are just line breaks, and not blank spaces nor tabs (unless there are some of this outside/before the conditional tag).

Also, you can do the conditionals inside the <title></title>, like this

<title><txp:if_section name="about">About us &mdash; Sitename
</txp:if_section><txp:if_section name="articles">Articles &mdash; Sitename
</txp:if_section><txp:if_section name="stellenanzeigen">Stellenanzeigen &mdash; itename
</txp:if_section></title>

But I’ve a question: what’s wrong with the white-space on the source? Nobody sees it. You could argue it adds some bytes to the page, but I think it is a despicable quantity…

Last edited by maniqui (2008-04-18 17:47:07)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#10 2008-04-18 17:55:51

stellaris
Member
Registered: 2008-03-06
Posts: 19

Re: [solved] Conditionals generate lots of whitespace in markup?

maniqui wrote:
But I’ve a question: what’s wrong with the white-space on the source? Nobody sees it. You could argue it adds some bytes to the page, but I think it is a despicable quantity…

It simply looks odd to me when displaying the source. If I show someone the source in FF, it looks like something went wrong, with the gaps there in place.

Offline

#11 2008-04-18 18:04:09

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: [solved] Conditionals generate lots of whitespace in markup?

There’s nothing wrong with the white-space maniqui. It’s just a question of personal taste. Some don’t like it and some don’t give a damn. It’s the same thing with page and form code, some like it all nicely indented the way their favourite text editor does it and some, like me, don’t give a damn. At the end of the day the only thing that really matters is that the software works and your site looks and works the way you want it to. :)

Last edited by thebombsite (2008-04-18 18:04:31)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#12 2008-04-18 18:05:56

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: [solved] Conditionals generate lots of whitespace in markup?

Do you have the HTML Tidy Extension for Firefox installed?
For me, it’s a must have.

So, if you have it installed, when you view the source, you can click on “Clean up page…” and then you will have the option to see a “clean” (indented) version of the code.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB