Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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 — Sitename</title> </txp:if_section>
<txp:if_section name="about"><title>>About us — 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 — 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
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 — 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 — Sitename</title></txp:if_section>
<txp:if_section name="articles"><title>Articles — Sitename</title></txp:if_section>
<txp:if_section name="stellenanzeigen"><title>Stellenanzeigen — 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 — 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 — Sitename</title></txp:if_section><txp:if_section name="articles">
<title>Articles — Sitename</title></txp:if_section><txp:if_section name="stellenanzeigen">
<title>Stellenanzeigen — itename</title></txp:if_section>
or
<txp:if_section name="about"><title>About us — Sitename</title>
</txp:if_section><txp:if_section name="articles"><title>Articles — Sitename</title>
</txp:if_section><txp:if_section name="stellenanzeigen"><title>Stellenanzeigen — 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
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 — Sitename
</txp:if_section><txp:if_section name="articles">Articles — Sitename
</txp:if_section><txp:if_section name="stellenanzeigen">Stellenanzeigen — 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)
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
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
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.
Offline