Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-05-31 18:05:04

atbradley
Plugin Author
From: Rhode Island, US
Registered: 2007-02-15
Posts: 34
Website

atb_if_form: Two simple conditional forms.

Lately, I’ve been writing Textpattern pages for relatively complex sites that do things like this:

<txp:if_section name="widgets,sprockets,thingies">
    <txp:hide>The widgets, sprockets, and thingies sections have their own special layouts.</txp:hide>
    <txp:output_form form='content-<txp:section />' />
<txp:else />
    <txp:hide>All the other sections look pretty much the same.</txp:hide>
    <txp:output_form form='content-default' />
</txp:if_section>

This plugin is designed to simplify this somewhat, and eliminate that list of section names (which is just one more thing for me to forget to update when I change the site). Hopefully, someone else will find it useful.

atb_if_form

A simple, hopefully self-explanatory conditional form:

<txp:atb_if_form name="someform">
	<p>someform exists.</p>
<txp:else />
	<p>someform doesn't exist</p>
</txp:atb_if_form>

atb_output_form_if_exists

Can be used exactly the same way as the built-in output_form tag, except it doesn’t raise an error if the form provided doesn’t exist:

<txp:atb_output_form_if_exists form='foo-<txp:section />'>
    This text will be available via the txp:yield tag in foo-[section].
</txp:atb_output_form_if_exists>

It can also be used with a txp:else tag:

<txp:atb_output_form_if_exists form='foo-<txp:section />'>
    This text will be available via the txp:yield tag in foo-[section].
<txp:else />
    <txp:output_form form="foo-default" />
</txp:atb_output_form_if_exists>

You can also follow this on GitHub.

Last edited by atbradley (2010-06-01 19:57:31)

Offline

#2 2010-06-03 22:18:11

aswihart
Member
From: Pittsburgh, PA
Registered: 2006-07-22
Posts: 345
Website

Re: atb_if_form: Two simple conditional forms.

Took me a second to get my head around this. Seems like this plugin is really useful as a kind of templating tool or if you are always changing your site around.

Like you said, you are left with not having to update an if_section tag when you change or add new sections. Just be consistent in naming your forms (which you would do anyway).

Also, your example code made me lookup what the txp:yield tag does, I think that was the last of the “new” tags that I hadn’t used, thanks for mentioning it.

Offline

#3 2010-06-04 07:39:00

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: atb_if_form: Two simple conditional forms.

to aswihart:

Also, your example code made me lookup what the txp:yield tag does, I think that was the last of the “new” tags that I hadn’t used, thanks for mentioning it.

  1. Your form_x – <div><txp:yield /></div>
  2. You have this: <txp:output_form form="form_x">Text for yield!</txp:output_form>
  3. You will get whis: <div>Text for yield!</div>

txp:yield is like you send some data to your form through form calling


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

Board footer

Powered by FluxBB