Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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.
- Your form_x –
<div><txp:yield /></div>
- You have this:
<txp:output_form form="form_x">Text for yield!</txp:output_form>
- 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