Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Using <txp:if_section> without making whitespace
Hi.
I’m using misc forms to populate certain page areas, notably keywords and meta data (things outside of the article context). I’m getting some unexpected behaviour with whitespace when I use if_section
in a series. I call a misc form, which looks like this:
<txp:if_section name="apple">Apple</txp:if_section>
<txp:if_section name="banana">Banana</txp:if_section>
<txp:if_section name="cherry">Cherry</txp:if_section>
<txp:if_section name="damson">Damson</txp:if_section>
What I expect to see is the current section name output, and nothing else. In the page source, each line that is parsed that doesn’t do anything creates a line of whitespace. So, if the ‘banana’ section is being viewed, I don’t just see Banana
, I see this in the source:
<whitespace>
Banana
<whitespace>
<whitespace>
…when all I expect to see is:
Banana
I use long forms (~30 sections listed in series) to do specific stuff so it’s resulting in lots of empty space in the page source. My markup code behind the scenes is tidy, valid and readable – I don’t know what I’m doing wrong here that makes the whitespace appear. I appreciate browsers parse the code in a human-viewable form, but it’s confusing to search bots when one meta data entry is spread across 30 lines :)
I could understand it if Textile is parsing the form line breaks as line breaks inside an article context, but this is going on in <head>
so I’m totally stumped.
Thanks in advance for any ideas.
PS: I hope all this talk of fruit has made you hungry…
(Updated for typos and some parts not making any sense)
Last edited by gaekwad (2010-10-13 13:13:19)
Offline
Re: Using <txp:if_section> without making whitespace
Nothing to do with you. It’s TXP’s modus operandi.
fwiw, some days it bugs the hell out of me too because each newline is another byte of my bandwidth wasted and sometimes it leads to blanks where you really don’t want them (e.g. when constructing conditional links: spaces appear inside the hyperlink unless you squish all the code up in the Page/Form). The source code of my software page has a huuuuge blank section where I load a form that contains nothing but <txp:variable />
declarations concerning each available plugin. Meh.
But then, equally, I’d probably complain more if I did want a space and TXP got rid of it so it’s just one of those things we have to live with at the moment.
I’ll have a banana instead and hope it quells the OCD monkey inside me.
Last edited by Bloke (2010-10-13 13:24:48)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Using <txp:if_section> without making whitespace
gaekwad wrote:
I don’t know what I’m doing wrong here that makes the whitespace appear.
There is nothing wrong in your code. You just happen to have line breaks in your code. You really can’t expect anything else if you use whitespace between the conditional blocks ;)
If you don’t want line breaks to appear, don’t use line breaks or strip them off.
For example, you can strip them away by using rah_replace plugin:
<txp:rah_replace from="
" to="">
<txp:if_section name="apple">Apple</txp:if_section>
<txp:if_section name="banana">Banana</txp:if_section>
</txp:rah_replace>
Offline
Re: Using <txp:if_section> without making whitespace
Thanks, dudes. Appreciate your time and input.
Offline
Re: Using <txp:if_section> without making whitespace
Hi Pete
If you write your code like this:
<txp:if_section name="apple">Apple</txp:if_section><txp:if_section name="banana">Banana</txp:if_section><txp:if_section name="cherry">Cherry</txp:if_section><txp:if_section name="damson">Damson</txp:if_section>
The line breaks will gone
Cheers
Offline
Re: Using <txp:if_section> without making whitespace
Bonjour, Dragondz – merci pour vos conseils.
Offline