Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-11-30 09:00:19

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

Test if a section has categories assigned to it

The main navigation for my site is created with a section list and category lists for the su navigation (drop downs). There are cases where a section doesn’t have any categories. What I want to do is, where sections have categories assigned, not create a link to that section and where they do not have categories I want there to be a link to that category.

I hope I explained myself well enough, here is the current txp code I’m using;

<txp:section_list break=”“ include_default=“1” default_title=“Home”>
<li<txp:if_section name=’<txp:section />’> class=“current”</txp:if_section>>
<txp:section link=“1” title=“1” />
<txp:category_list children=“0” wraptag=“ul” section=”<txp:section title=“0” />” break=“li” parent=”<txp:section title=“0” />” exclude=’<txp:section title=“0” />’ />
</li>
</txp:section_list>

Offline

#2 2009-11-30 10:51:47

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,549
Website GitHub Twitter

Re: Test if a section has categories assigned to it

Hi

You can use chh_if_data plugin or use txp:variable like this:

<txp:variable name="cato" value='<txp:category_list children=“0” section='<txp:section />' parent='<txp:section title=“0” />' exclude=’<txp:section title=“0” />’ />' />
<txp:if_variable name="cato" value="">
<txp:else />
<txp:category_list children=“0” wraptag=“ul” section=”<txp:section title=“0” />” break=“li” parent=”<txp:section title=“0” />” exclude=’<txp:section title=“0” />’ />
</txp:if_variable>

Havent tested but the idea is there.

Chh_if_data need less code to write.

Cheers

Offline

#3 2009-11-30 11:55:48

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

Re: Test if a section has categories assigned to it

Thanks for the suggestion re: the plugin but I can’t get it to work. Not sure it will within the scope of how the navigation is created

Offline

#4 2009-11-30 20:31:57

leafy_loader
Member
Registered: 2008-09-25
Posts: 96

Re: Test if a section has categories assigned to it

<txp:section_list break=”“ include_default=“1” default_title=“Home”>
<txp:variable name=“cato” value=’<txp:category_list children=“0” wraptag=“ul” section=”<txp:section title=“0” />” break=“li” parent=”<txp:section title=“0” />” exclude=”<txp:section title=“0” />” />’ />
<txp:if_variable name=“cato” value=”“>
<txp:section link=“1” title=“1” />
<txp:else />
<txp:section />
<txp:category_list children=“0” wraptag=“ul” class=”“ section=”<txp:section title=“0” />” break=“li” parent=”<txp:section title=“0” />” exclude=’<txp:section title=“0” />’ />
</txp:if_variable>
</txp:section_list>

tried using the txp variable tag but thats not giving me the desired results either

Offline

#5 2009-11-30 20:43:57

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

Re: Test if a section has categories assigned to it

Hi.

When using txp tags inside txp tags you need to use single quotes, and on each deeper level, use an extra pair of quotes (aka “escape” the quotes):

Examples:

<txp:tag1 attr='<txp:tag2 />' />
<txp:tag1 attr='<txp:tag2 foo="bar" />' />
<txp:tag1 attr='<txp:tag2 foo="bar" kling=''<txp:klang />'' />' /> // <txp:klang /> is wrapped by two single quotes on each side.

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB