Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-07-01 14:22:08

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

<txp:output_form form="form_a, form_b" />

As a theme plan is building, how about making the <txp:output_form /> tag accepting a comma separated list of form names; the theme I’m working on has a variable/pref in which you can choose to display different forms to compose your sidebar, but for now, I have to play with rah_repeat.

<!-- user pref -->
<txp:variable name="sidebar_widgets" value="bio, contact, popular, tags" />

<!-- code -->
<txp:rah_repeat value='<txp:variable name="sidebar_widgets" />'>
	<txp:output_form form='<txp:rah_repeat_value />' />
</txp:rah_repeat>

Last edited by NicolasGraph (2015-07-01 14:23:59)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#2 2015-07-01 14:45:04

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

Re: <txp:output_form form="form_a, form_b" />

Honestly, I don’t see the widespread appeal of this. It would be the only tag to support a comma-separated form attribute, thus confusing users of other tags with the same attribute.

Sine this is arguably a niche concept, you’re better off either:

  1. sticking with your current approach
  2. having a variable per form and using <txp:if_variable> to decide which to display
  3. using <txp:yield /> and either a “repeat” plugin or a “switch… case” system to choose between the options.

Or a combination of the above. Bear in mind that, for performance reasons, you may be better off with option (2), or at least combining the approaches (2) and (3) to minimise the number of <txp:output_form> tags. Each one incurs a database round-trip.

Viz:

<!-- user pref -->
<txp:variable name="sidebar_widgets" value="bio, contact, popular, tags" />

<txp:rah_repeat value='<txp:variable name="sidebar_widgets" />'>
    <txp:output_form form="sidebars"><txp:rah_repeat_value /></txp:output_form>
</txp:rah_repeat>

And in Form sidebars:

<txp:variable name="chosen"><txp:yield /></txp:variable>

<txp:if_variable name="chosen" value="bio">
   <div class="widget">
      // Output some bio stuff here
   </div>
</txp:if_variable>

<txp:if_variable name="chosen" value="contact">
   <div class="widget">
      // Output contact info here
   </div>
</txp:if_variable>
...

Although it results in a longer Form, it’s much more efficient as there’s only one <txp:output_form> call, which is cached by Txp after first fetch. New options can be added to the end of the sidebars Form whenever you need new content, so it also has the benefit that your sidebar content is encapsulated in a single place when extending the site or making modifications to existing sidebar widgets.

How’s that as an alternative?


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

#3 2015-07-01 15:23:51

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: <txp:output_form form="form_a, form_b" />

Bloke wrote #292444:

It would be the only tag to support a comma-separated form attribute, thus confusing users of other tags with the same attribute.

That’s right.

How’s that as an alternative?

Thanks; it’s a good case for me to learn more about <txp:yield /> because I don’t understand the way you use it…

Edit: I’m starting to understand the ‘powerness’ or <txp:yield />. One more tag to be friend with…

Last edited by NicolasGraph (2015-07-01 15:46:47)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#4 2015-07-01 15:46:02

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

Re: <txp:output_form form="form_a, form_b" />

NicolasGraph wrote #292448:

to learn more about <txp:yield /> because I don’t understand the way you use it…

OK. It’s just a way of retrieving content passed in from <txp:output_form>’s container.

If you look at the way the <txp:output_form> is constructed in my example, you’ll see I inject the rah_repeat value (which is derived from your pref variable) into its container.

When the designated Form is read, it does nothing special except if it hits a <txp:yield /> tag whereby it replaces that tag with the contents passed into the Form. That’s pretty much it.

In this case, I’m assigning the individual value from rah_repeat to a variable (called chosen) and then repeatedly testing that value with <txp:if_variable> to find a match.

Does that help?


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

#5 2015-07-01 16:01:31

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: <txp:output_form form="form_a, form_b" />

Bloke wrote #292451:

Does that help?

Yes thanks, I need some time but I always end up to understand. :)
(previous reply was wrong)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#6 2015-07-01 16:15:58

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: <txp:output_form form="form_a, form_b" />

Bloke wrote #292444:

How’s that as an alternative?

Just one thing about your code; I gave it a try but I realised that I can’t manage the order of the widgets with the theme pref in this way. I’ll see how important it is regarding to the performance gain.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#7 2015-07-01 17:17:33

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

Re: <txp:output_form form="form_a, form_b" />

NicolasGraph wrote #292460:

I can’t manage the order of the widgets with the theme pref in this way.

Quite true. That would require an iterative approach (rah_repeat) rather than a select-case approach in the form. If order is important you might not have many other options than to do something along the lines of what you originally proposed (although I’m sure Oleg will be able to figure something out with etc_query!)


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

Board footer

Powered by FluxBB