Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
[Solved] Call a form recursively
I’m using several calls to a same form, via <txp:article_custom />
for layout reasons.
My problem is about coding esthetic: currently, I’m calling several times (many) the form by setting different limit
and offset
attributes… (it’s bad)
Is there a better solution: a recursive one (maybe with the help of a variable
)?
Last edited by Pat64 (2019-10-26 19:59:36)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Call a form recursively
It depends what you’re trying to do ;-) but if you’re trying to segment your list of articles to sandwich something in-between, you could try using a variable as a counter that you advance with each iteration, and then in your form, test with if_variable against the current counter number where you need to insert something.
Something like:
<txp:variable name="counter" value="1" />
<txp:article_custom limit="20" section="news" break="">
<txp:if_first_article>
<!-- first four articles as features -->
<section class="article_features">
</txp:if_first_article>
<article>
<txp:title wraptag="h2" />
<txp:body />
</article>
<txp:if_variable name="counter" value="4">
</section>
<!-- short teaser previews for articles 5-10 -->
<section class="article_teasers">
</txp:if_variable>
<txp:if_variable name="counter" value="10">
</section>
<!-- next ten articles as simple linklist -->
<section class="article_list">
</txp:if_variable>
<txp:if_last_article>
</section>
</txp:if_last_article>
<!-- advance counter by 1 -->
<txp:variable name="counter" add="1" />
</txp:article_custom>
If there’s some regularity to it, you might want to try using txp:evaluate
to test against “divisible by” etc.
This is just a simple example, but you could do more complex things:
- To output different article forms, use
if_variable … else
(if necessary nesting) tooutput_form
different forms depending on the counter. - To use the same article form but give each type a different class, e.g. “feature”, “teaser”, “simple”, set a variable for the class to use at the beginning, then change the variable’s value as the counter advances…
Is that the kind of thing you were thinking of?
TXP Builders – finely-crafted code, design and txp
Online
Re: [Solved] Call a form recursively
There should be no problem calling form recursively (up to some depth) since 4.7. Sorry, I have misread it. A variant of @jacob suggestion when you only need to change some value (say, limit
) is to predefine <txp:variable name="limit_1" value="10" />
etc outside your form, and then plug the counter inside it:
<txp:variable name ="counter" add />
<txp:article_custom limit='<txp:variable name=''limit_<txp:variable name ="counter" />'' />' />
Offline
Re: [Solved] Call a form recursively
Thank you.
It seems in my case I could combine both advices ;)
The Jakob’s one with Oleg’s the one on this forum page (second example: https://forum.textpattern.com/viewtopic.php?pid=302446#p302446)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Call a form recursively
I found a solution (for my needs).
Into my page
template:
<txp:variable name="counter" value="0" />
<txp:article breakby="3" breakform="default" />
<txp:variable name="counter" value="0" />
<txp:article breakby="3" breakform="default" offset="3" />
<txp:evaluate query='<txp:variable name="counter" /> = 3'>
<txp:else /></div></txp:evaluate>
And here is my default
form:
<txp:evaluate query='<txp:variable name="counter" /> = 0'>
<div class="r">
</txp:evaluate>
<txp:variable name="counter" value='<txp:evaluate query=''<txp:variable name="counter" /> + 1'' />' />
<txp:evaluate query='<txp:variable name="counter" /> <= 3'>
<div class="c">
<h2><txp:title /></h2>
</div>
<txp:else />
</div>
<txp:variable name="counter" value="0" />
</txp:evaluate>
But I don’t know if it’s an academic TXP practice (the best usage)?
My layout must be like this shema:
<div class="r">
<div class="c">
<h2>Title</h2>
</div>
<div class="c">
<h2>Title</h2>
</div>
<div class="c">
<h2>Title</h2>
</div>
</div>
And so on, recursively.
Last edited by Pat64 (2019-10-26 17:28:46)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Call a form recursively
IMO, you can get it just with
<txp:article break="div" breakclass="r" breakby="3">
<div class="c">
<h2><txp:title /></h2>
</div>
</txp:article>
Offline
Re: [Solved] Call a form recursively
Yes. Just perfect!
Thank you lot, Oleg.
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Call a form recursively
That’s way more succinct!
breakby
(and breakform
) are two attributes I seem to have missed. Useful stuff!
TXP Builders – finely-crafted code, design and txp
Online
Re: [Solved] Call a form recursively
jakob wrote #319848:
That’s way more succinct!
breakby
(andbreakform
) are two attributes I seem to have missed. Useful stuff!
Thank you Jakob! Exactly the same for me… (I was thinking I’m a very bad TXP user).
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Offline
Pages: 1