Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-12-06 23:37:39

cellseven
Member
From: St. Louis
Registered: 2006-12-05
Posts: 20
Website

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*orgCRAP

Offline

#2 2006-12-06 23:45:36

dbulli
Member
Registered: 2004-11-22
Posts: 195
Website

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

#3 2006-12-06 23:53:25

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: txp:elseif ? is this possible?

The dbulli’s suggestion won’t work because you can’t nest the same conditionals in TxP.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2006-12-07 00:01:35

dbulli
Member
Registered: 2004-11-22
Posts: 195
Website

Re: txp:elseif ? is this possible?

manqui … beat me to answer my won question =)

Conditional_Tags Nesting

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

#5 2006-12-07 00:09:09

cellseven
Member
From: St. Louis
Registered: 2006-12-05
Posts: 20
Website

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*orgCRAP

Offline

#6 2006-12-07 00:19:31

dbulli
Member
Registered: 2004-11-22
Posts: 195
Website

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

txp:section_list + active_class not good enough


nuff-respec ::: dannyb

Offline

#7 2006-12-07 00:35:05

cellseven
Member
From: St. Louis
Registered: 2006-12-05
Posts: 20
Website

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*orgCRAP

Offline

#8 2006-12-07 01:00:15

dbulli
Member
Registered: 2004-11-22
Posts: 195
Website

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

#9 2006-12-07 03:03:36

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

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

#10 2006-12-07 03:09:35

dbulli
Member
Registered: 2004-11-22
Posts: 195
Website

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

#11 2006-12-07 05:12:25

cellseven
Member
From: St. Louis
Registered: 2006-12-05
Posts: 20
Website

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*orgCRAP

Offline

Board footer

Powered by FluxBB