Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-10-19 15:31:16

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,361
Website

[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

#2 2019-10-19 16:25:57

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,854
Website

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) to output_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

Offline

#3 2019-10-19 16:40:28

etc
Developer
Registered: 2010-11-11
Posts: 3,714
Website

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" />'' />' />

Online

#4 2019-10-19 19:42:01

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,361
Website

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

#5 2019-10-26 16:10:56

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,361
Website

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

#6 2019-10-26 19:49:47

etc
Developer
Registered: 2010-11-11
Posts: 3,714
Website

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>

Online

#7 2019-10-26 19:59:11

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,361
Website

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

#8 2019-10-27 09:54:56

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,854
Website

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

Offline

#9 2019-10-27 12:37:01

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,361
Website

Re: [Solved] Call a form recursively

jakob wrote #319848:

That’s way more succinct!

breakby (and breakform) 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

#10 2019-10-27 13:12:47

etc
Developer
Registered: 2010-11-11
Posts: 3,714
Website

Re: [Solved] Call a form recursively

Pat64 wrote #319849:

(I was thinking I’m a very bad TXP user).

Nope, I’m just a very bad documenter. Note that breakform is still experimental, for braves :-)

Online

Board footer

Powered by FluxBB