Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-12-01 19:46:40

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

[howto] Assign active class for 2 sections to a single item in a section_list

I was trying to get Textpattern to generate a section-based navigation list where one of the links was active when browsing two distinct sections. I accidentally deleted the preamble to this when I made some code corrections to the post, but this is the solution I came up with (HTML attributes indented for clarity):

<txp:section_list
	break="li"
	class="nav-main"
	default_title="Home"
	include_default="1"
	wraptag="ul"
	sections="about,articles,news,podcast,subscribe,etc,etc,etc">
<txp:variable name="this-nav-link"><txp:section/></txp:variable>
<a
	href="<txp:site_url/><txp:section/>/"<txp:if_section name='<txp:section/>'>
	class="active"</txp:if_section><txp:if_variable name="this-nav-link" value="articles"><txp:if_section name="issues">
	class="active"</txp:if_section></txp:if_variable>>
	<txp:section title="1"/>
</a>
</txp:section_list>

There may be even better ways to do this, but I wanted to post this here because the forum’s memory may be longer than mine, and I may need to look this up again.

If there are better ways to make this happen, feel free to break it down!

Last edited by johnstephens (2009-12-01 19:51:10)

Offline

#2 2009-12-01 20:13:42

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Re: [howto] Assign active class for 2 sections to a single item in a section_list

Memo: href="<txp:site_url/><txp:section/>/" will give undesirable results when linking Home. Use this instead:

href="<txp:site_url/><txp:if_variable name="this-nav-link" value="default"><txp:else/><txp:section/>/</txp:if_variable>"

Offline

#3 2009-12-01 20:22:13

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [howto] Assign active class for 2 sections to a single item in a section_list

Nice one!

Mind if I move it to How-tos and Examples?

Offline

#4 2009-12-01 20:29:03

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: [howto] Assign active class for 2 sections to a single item in a section_list

Errm..TXP Tip? ;-)

Offline

#5 2009-12-01 20:31:15

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Re: [howto] Assign active class for 2 sections to a single item in a section_list

Els: No problem. I started composing the post before I figured it out— I was posting it here for help!

Jonathan: Sure, I’ll write it up right now.

Offline

Board footer

Powered by FluxBB