Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-11-17 15:15:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Greedy txp:hide around conditional tags

This isn’t necessarily a problem as such, but I’m not sure if it’s just me or if anyone else’s TXP works like this.

Say I have some tags/output in a conditional statement. Let’s keep it simple:

<txp:if_section name="test, wip, stuff">

   <meta name="robots" content="noindex,nofollow" />

</txp:if_section>

Say I want to make the meta tag appear on all pages because I’ve copied the site to a testing domain that I don’t want to be indexed. One would expect:

<txp:hide><txp:if_section name="test, wip, stuff"></txp:hide>

   <meta name="robots" content="noindex,nofollow" />

<txp:hide></txp:if_section></txp:hide>

to hide the conditional tags and leave the meta tag exposed. Yet on my test install it still ignores the meta tag. In fact, no matter what I put between the two commented out conditionals — txp:tags, HTML tags, raw text — it’s ignored.

The tag trace says:

<txp:hide>
</txp:hide>
<txp:hide>
</txp:hide>

So clearly it sees the two sets of <txp:hide> tags as separate entities but it appears to be swallowing anything in between them. This appears to only happens if you comment out a conditional tag pair — any other type of content inside each of the hide tags is fine.

Is this too obscure to worry about? Is it just me? Does it matter?


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

#2 2009-11-17 16:29:48

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Greedy txp:hide around conditional tags

Bloke wrote:

Is this too obscure to worry about? Is it just me? Does it matter?

Faster parser versus better, “but invalidish” hide; I vote for how it is currently.

As tags are functions, your example seems to me really bad (fix against standards).

Offline

#3 2009-11-17 16:36:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Greedy txp:hide around conditional tags

Gocom wrote:

Faster parser versus better, “but invalidish” hide; I vote for how it is currently.

Fine by me. I didn’t think it was ‘broken’ as such. This is a pretty perverse use of the hide tag and my example was deliberately simple. Just wanted to make sure that it wouldn’t confuse people in a real-world situation if you were, for example, commenting out a few huge chunks of code that included a conditional tag.


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

#4 2010-07-30 01:19:30

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Greedy txp:hide around conditional tags

Sorry Stef, the special medicine has worn off & I’ve had a coffee ;-) …

Bloke wrote:

Is this too obscure to worry about? Is it just me? Does it matter?

No. No. Yes it does.

I think this may the same problem:

<txp:hide><txp:smd_switch item='<txp:section />'></txp:hide>

which has the effect of totally messing up the page.

Gocom wrote:

“invalidish hide” …

What’s invalid about it? The TXP manual states:

The hide tag is a container tag which is used to suppress the interpretation of all enclosed contents.

Gocom wrote:

As tags are functions, your example seems to me really bad (fix against standards).

I disagree. There’s nothing “bad” about it & from a user’s point of view I shouldn’t have to care how tags are implented. They should “do what it says on the tin”.

The ability to reliably comment out code is basic stuff!

Just to stir things up a further, I think that:

  1. It’s a bug & <txp:hide> needs to be fixed OR
  2. Another reliable method of commenting out code should be available AND AT THE VERY LEAST
  3. Textbook should be updated to reflect the deficiences in <txp:hide>

Offline

#5 2010-07-30 11:25:54

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

Re: Greedy txp:hide around conditional tags

It’s not a bug, but the result of improper nesting of taqs. <txp:hide> is a tag just like any other.
You can’t do <b><i>text</b></i> in (X)HTML either.
The tag parser assumes proper nesting, so if you feed it something like this:

<txp:hide><txp:if_section name="test, wip, stuff"></txp:hide>
   <meta name="robots" content="noindex,nofollow" />
<txp:hide></txp:if_section></txp:hide>

The parser interprets this as:

<txp:hide>
  <txp:if_section name="test, wip, stuff"></txp:if_section>
  <meta name="robots" content="noindex,nofollow" />
  <txp:hide></txp:hide>
</txp:hide>

Which is why the meta tag is hidden as well.

I’d say: “won’t fix” (and document the limitations in textbook)
Another limitation (again: for all tags) is that the open/close container tags cannot cross a form boundary: if you have a opening tag in a template and a closing tag in an included form (or the other way around), it won’t work as planned (unless you planned for it not to work).

These things can be fixed, but you’d get a 3-stage parser: one stage to flatten the template and all included forms into one big template, a second stage to remove all the hidden content and then a third stage to finally parse all that remains. That can’t be fast.

Offline

#6 2010-07-30 11:41:42

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Greedy txp:hide around conditional tags

gomedia wrote:

What’s invalid about it? The TXP manual states:

In the current parser it is. It’s just a normal tag. To be able to implement comments, you would need yet another layer to the parser. The way it’s used in the example isn’t correct as it is a tag, and as such it shouldn’t work.

Offline

#7 2010-07-30 13:18:16

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Greedy txp:hide around conditional tags

Then the deficiencies of the <txp:hide> tag need to be documented.

Offline

Board footer

Powered by FluxBB