Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
txp:elseif ? is this possible?
I’m wondering if this is possible, I see that if you have two different options for a page you can do an if/else and you end up with the desired results. But what if you have different needs for more than two sections? I’d love to do something similar to the code below.
<txp:if_section name="blah1">
<txp:article_custom limit="32" sort="Posted asc" />
<txp:elseif_section name="blah2">
<txp:article_custom limit="2" />
<txp:elseif_section name="blah3">
<txp:article limit="7" />
<txp:else />
<txp:article />
</txp:if_section>
Unfortunately that doesn’t work, I sort of/kind of/but not so much have it working with the code posted below. Does anyone out there have a solution for this, or do I start hacking code to get what I want/need/desire?
<txp:if_section name="blah1">
<txp:article_custom limit="32" sort="Posted asc" />
<txp:else />
</txp:if_section>
<txp:if_section name="blah2">
<txp:article_custom limit="2" />
<txp:else />
</txp:if_section>
<txp:if_section name="blah3">
<txp:article limit="7" />
<txp:else />
</txp:if_section>
And I will admit, I’ve looked all over txp forums, textbook and google for an answer to this, I am not one who likes to ask questions if I can find the answers myself.
Thanks in advance to anyone able to point me in the right direction.
Last edited by cellseven (2006-12-06 23:39:56)
jack [at] cell7*org — CRAP
Offline
Re: txp:elseif ? is this possible?
What you are looking for is what is known as a switch … that would be nice … you could possibly fake it like this …
<txp:if_section name="blah1">
<txp:article_custom limit="32" sort="Posted asc" />
<txp:else />
<txp:if_section name=“blah2”>
<txp:article_custom limit=“2” />
<txp:else />
<txp:if_section name=“blah3”>
<txp:article limit=“7” />
</txp:if_section>
</txp:if_section>
</txp:if_section>
nuff-respec ::: dannyb
Offline
Re: txp:elseif ? is this possible?
The dbulli’s suggestion won’t work because you can’t nest the same conditionals in TxP.
Offline
Re: txp:elseif ? is this possible?
manqui … beat me to answer my won question =)
So what you have should work but you don’t need the else … and you need to put EVERY section in there … because the else is per single section… so you are in the right direction …
Other way I know is a different txp_page for each section … or a page per two sections so you can have one if/else per page.
nuff-respec ::: dannyb
Offline
Re: txp:elseif ? is this possible?
Yeah, maniqui I initially thought of nesting/stacking like that but I didn’t try it yet, I suppose it would be a waste of time at this point. And dbulli, I am currently using different txp_pages for each section, but that’s bothersome during development because I have to remember to update the navigation on every page when I add/remove something. So I’m going to stick with it, currently my sites default section, wedding countdown and wishlists are all conditionally run from the default template, but it causes odd counts from the limit=“x” part, too many show up in both so I must do some more testing.
jack [at] cell7*org — CRAP
Offline
Re: txp:elseif ? is this possible?
You shouldn’t have to redo navigation … that’s where the beauty of forms comes in … look into MISC form … i wrote up something earlier … and while i thought of it on my very own … i know many people use the same technique … but get your nav into a FORM …
nuff-respec ::: dannyb
Offline
Re: txp:elseif ? is this possible?
Perfect! I can have my different pages and then use this method for navigation! I struggled with just doing some raw php include(‘file.php’) but that proved not to work no matter what my site settings/prefs were. I am still quite new to TXP so I’m glad there are folks out here like you to help a n00b along!
jack [at] cell7*org — CRAP
Offline
Re: txp:elseif ? is this possible?
ha .. you only caught me on a good week =) … i only started looking into TxP again within the last month after my new baby mac … and did the redesign … wait till next month …
so much for me to learn too .. but textbook thing is a thing of beauty …
btw… slick sliding articles on home … now where is my padding ;)
nuff-respec ::: dannyb
Offline
Re: txp:elseif ? is this possible?
Templating is so much fun, since there are multiple ways of doing the same thing, each with their own merits. I like to keep my menu CSS pretty small, so I use:
<ul id="nav">
<li><a <txp:if_section name="foo">class="active"</txp:if_section>href="<txp:site_url />foo/">Foo</a></li>
<li><a <txp:if_section name="bar">class="active"</txp:if_section>href="<txp:site_url />bar/">Bar</a></li>
</ul>
But if you’ve got image replacement going, it might not be worth it to add more conditionals, as it’d be just as easy to plop it in the CSS.
Also, you can place if_search
on your body tag (or other HTML), if you want to highlight search terms differently.
<body <txp:if_search>class="search"</txp:if_search>>
CSS:
body.search #someContainer strong {
font-size: ginormous;
}
Offline
Re: txp:elseif ? is this possible?
sweet … jm …
that would make my html output smaller+nicer but my form bigger + ugler … from a user perspective that’s probably that’s probably what i shoulda done … too lazy to change now =) … after all i wrote bout it ….
templating is like sql … such a small languages so you need to get creative
nuff-respec ::: dannyb
Offline
Re: txp:elseif ? is this possible?
I’ve thought of doing come active classing on my nav, maybe will get around to it after I have everything else where I want it, at present my navigation is all css/text based so it’s cake as far as the code goes, plus the loadtime is very quick. This is spawning a few more ideas for “features” in my mind, and maybe something I can write a plugin for in the future. I imagine with the help I’m getting on this site I’d feel remiss if I didn’t give something back eventually.
jack [at] cell7*org — CRAP
Offline
Pages: 1