Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-01-27 13:06:32

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,787
Website

Using the mothership placeholder for tag attributes in loops?

Another post, this time about replacing rah_repeat with loops.

I want to loop over a comma-separated string and then use each item to output a txp:variable with the corresponding name, e.g.

<txp:variable name="wochentage" value="mo,tu,we,th,fr,sa,su" breakby="," breakform="weekday_item" output />

and weekday_item does this:

<txp:if_variable name='business_hours_<+>'>
    <p>
        <txp:evaluate wraptag="span" class="weekday" escape="upper"><+></txp:evaluate>
        <txp:variable name='business_hours_<+>' trim="/([ -]+)/" replace="&thinsp;–&thinsp;" /> O'clock
    </p>
</txp:if_variable>

I can output the <+> (mothership) on its own, but if I try and use it in a tag attribute, I have no luck*. The variables business_hours_mo, business_hours_tu … are all already defined and accessible. They work if I supply them manually.

Interestingly, the <+> is not capitalised with escape="upper" either.

(this is all with txp 4.9-dev)

*Oh, I also tried doing:

<txp:variable name="weekday">business_hours_<+></txp:variable>
<txp:variable name=name='<txp:variable name="weekday" />' trim="/([ -]+)/" replace="&thinsp;–&thinsp;" /> O'clock

But also no luck in this tag-in-tag combination. If I add output to the first weekday I can verify that the generated variable names are correct, but are just not being used in the tag-in-tag combination.


TXP Builders – finely-crafted code, design and txp

Offline

#2 2025-01-27 13:45:16

etc
Developer
Registered: 2010-11-11
Posts: 5,316
Website GitHub

Re: Using the mothership placeholder for tag attributes in loops?

The mothership replacement happens after the form is parsed. Try replacing <+> with <txp:yield item />.

Offline

#3 2025-01-28 22:31:32

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,787
Website

Re: Using the mothership placeholder for tag attributes in loops?

etc wrote #338938:

The mothership replacement happens after the form is parsed. Try replacing <+> with <txp:yield item />.

That explains it, and the solution feels a bit more intuitive too (well, more like rah_replace_value).

Thank you (again)!


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB