Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Need something in a page that's determined by article form override
I need to do something at the PAGE level that’s conditional on a setting I need to be able to make per-article, preferably with a form override. An “if individual article form=X” type of thing.
Basically I want to do something different in the layout for certain articles, not tied to section, category, or anything like that.
Here comes the specific example. I’m turning this page into a TXP site. The big graphic at the top comes before a bunch of wrapper divs and other stuff that is part of the page, not the article form.
Any ideas?
Yes, I have tried turning it off and on.
Offline
Re: Need something in a page that's determined by article form override
Maybe you could use the if_article_id
tag like this:
<txp:if_article_id id="10,51,200">These are special<txp:else />These are ordinary</txp:if_article_id>
Offline
Re: Need something in a page that's determined by article form override
When you say at the page level, you mean above the normal article flow? i.e. before your <txp:article>
tag?
There’s nothing to stop you using the article tag twice, the first time as a container tag where you do your logic but don’t display anything:
<txp:article>
<txp:if_individual_article>
<txp:variable name="whatever"><txp:custom_field name="my_cf" /></txp:variable>
</txp:if_individual_article>
</txp:article>
...
<!-- some time later -->
...
<txp:if_variable name="whatever" value="">
<txp:else />
I've been set to <txp:variable name="whatever" />
</txp:if_variable>
...
<txp:article />
In the container (or Form if you prefer) you can use <txp:if_article_id>
to test if the article’s ID matches one particular value, or use a plugin like smd_if to check if it’s one of a number of values. As long as you first check if you’re in individual article context, that’ll work.
Alternatively, if you don’t want the overhead of two article calls on each page, move your <txp:article>
tag higher up the page (or use it as a container that encapsulates more of the page) and just use <txp:output_form>
in your default Form to display the various ‘headerish’ pieces of content first, then output your wrapper markup and article-specific stuff afterwards. i.e.
<section role="nav">
<txp:output_form form="navigation" />
</section>
<txp:article>
<section role="banner">
<txp:output_form form="banner_image" />
</section>
<main>
<txp:title />
<txp:body />
</main>
</txp:article>
<txp:output_form form="footer" />
If you can dream it and there’s a tag/plugin for it, you can do it :-)
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
Re: Need something in a page that's determined by article form override
Wow, that is impressive and so far over my head I can’t even figure out where to begin implementing it.
I did figure out something that works for me tho. I wanted it to be easy for the article editors to make the selection, but since Override Form wasn’t going to work, I installed glz_custom_fields which allows me to create a checkbox custom field for when they want to enable this feature. Then I added this to the page template:
<txp:if_individual_article>
<txp:if_custom_field name="Article Image is wide" value="Wide">
<div id="header-img" style="background-image:url(<txp:image_url id='<txp:custom_field name="article_image" />' />)"></div>
</txp:if_custom_field>
</txp:if_individual_article>
(I also found the image_url snippet which allows me to use the article_image as a div background.) Happiness!
Yes, I have tried turning it off and on.
Offline
Re: Need something in a page that's determined by article form override
alesh wrote #282563:
Wow, that is impressive and so far over my head I can’t even figure out where to begin implementing it.
I say that a lot around these parts.
Offline