Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Matching the spaceship <+> to something
I have a list:
<txp:variable name="topsearches" trim>
Term 1, Term2, Term 3, <a href="/special-link">Term 4</a>, Search Term 5, <a href="/another/special-link">Some Term 6</a>, ....
</txp:variable>
Then later, split on comma and pass each term to a form so I can offer a bunch of potted ‘top searches’ alongisde my <txp:search_input> tag:
<txp:variable name="topsearches" breakby="," breakform="topsearch_item" trim />
My topsearch_item form receives the spaceship, right? And I want to test if the passed value is a fully-formed href already (in which case, spit it out verbatim) otherwise, treat the passed value as a search term and wrap it in an anchor with a q= param.
I’m having a devil of a time trying to test the value. Is the spaceship operator special in some way because of its nature?
Things I’ve tried:
<txp:variable name="spaceship"><+></txp:variable>
<if::variable name="spaceship" match="pattern" value="^\<a.*$"> ...
<txp:variable name="spaceship"><+></txp:variable>
<if::variable name="spaceship" match="pattern" value="href"> ...
<txp:variable name="spaceship"><+></txp:variable>
<if::variable name="spaceship" escape="a" value=""> ...
<txp:variable name="spaceship"><+></txp:variable>
<if::variable name="spaceship" escape="tags" value=""> ...
<txp:variable name="spaceship"><+></txp:variable>
<if::variable name="spaceship" escape="tags" value="<+>"> ...
Nothing. It always treats both anchors and raw values as the same, and returns the same value for both raw and processed input.
Confusingly, if I output the variables in my form, and strip off tags or the ‘a’ tag, it deletes the raw text from between them too, which is contrary to what the tag docs say should happen with the escape attribute.
If I hard-code <txp:variable name="spaceship"><a href="/something">SOME LINK</a></txp:variable> and print out the variables, they work fine and return only SOME LINK when escape="tags" and escape="a" are used, so I expect the spaceship operator behaves in some way differently.
Is there any way out of this conundrum? Any better approaches?
P.S. I’d also like to somehow safely url-encode the passed value so it can be included in the q= but not escape the term that appears as the link. So far I just output: <a href="?q=<+>"><+></a> which means the q= param has spaces in it. It works, but they ideally should be + symbols.
Last edited by Bloke (2026-01-03 17:21:08)
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: Matching the spaceship <+> to something
I think I’ve made that mistake before and if I recall rightly, I think you need to use:
<txp:yield item />
in place of <+> in your breakform.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Matching the spaceship <+> to something
jakob wrote #342078:
I think you need to use:
<txp:yield item />...in place of<+>in your breakform.
Bingo, thank you!
<txp:variable name="spaceship" escape="a"><txp:yield item /></txp:variable>
<if::variable name="spaceship" value='<txp:yield item />'>
treat as a query string and wrap it in an anchor
<txp:else />
<+>
</if::variable>
And, bonus points because <txp:yield item escape="lower, url" /> also url-encodes the input suitable for the q= parameter. Woot!
Last edited by Bloke (2026-01-03 17:47:02)
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