Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2005-11-13 04:32:04
- sersam
- New Member
- Registered: 2005-03-08
- Posts: 6
filter a section_list output with substring?
How do I filter a section_list (or category list) output with some string? E.g. with “-en” substring for multilingual site? To view only english sections with “-en” suffix?
Offline
Re: filter a section_list output with substring?
So give me an idea of how your categories and/or sections naming convention works. Are you using the <code><txp:section_list /><txp:category_list /></code> tags for your current output? Are we going to be in specific sections for this output?
Last edited by thebombsite (2005-11-13 05:48:29)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
#3 2005-11-13 07:15:59
- sersam
- New Member
- Registered: 2005-03-08
- Posts: 6
Re: filter a section_list output with substring?
> thebombsite wrote:
> So give me an idea of how your categories and/or sections naming convention works.
I am using “-ru” and “-en” suffixes for sections and a category tree (without any plug-ins:) in both languages for my content organization (en & ru are root entriesfor categories tree). At best I want dynamically generate menu from section list according to browser address string content (mysite.com/art-ru for russian and mysite.com/art-en for english) or may be from browser’s settings. If this is too hard I want filter for -ru or -en simply.
> Are you using the <code><txp:section_list /><txp:category_list /></code> tags for your current output?
I am using <code><txp:section_list /></code> for main menu. I understand that I can output category lists inside “-ru” and “-en” sections in right language.
>Are we going to be in specific sections for this output?
I use it as main menu, so it must work on all pages in my case.
It looks like this:
<code>If (browser’s language is ru or address string contains “-ru/”) output (section_list items contains “-ru” (title for this section) or something else) else output (section_list items contains “-en” (title) or something else)</code>
Last edited by sersam (2005-11-13 08:13:27)
Offline
Re: filter a section_list output with substring?
I think, though I haven’t long got out of bed, that generating a category list wouldn’t be a problem. You could use the same technique as the other solution I gave you last night though I also think you would need to use <code><txp:article_custom /></code>. This would mean you would need to specify the section attribute but you could do that with <code>section=”<txp:section />”</code>.
A section listing is more difficult. I think you would need some kind of PHP to search for the “-en” or “-ru” part of the string and PHP isn’t my strong point.
You could do it manually by creating 2 small forms with the different section listings in them then calling them into your menu with a conditional like so:-
<code>
<txp:if section name=“section-en1,section-en2,section-en3”
<txp:output_form form=“listing-en” />
<txp:else />
<txp:output_form form=“listing-ru” />
</txp:if_section></code>
<br />
If you have sections that don’t have the “-en” and “-ru” suffix you may need to remove the “else” tag and have 2 separate blocks so neither form appears in those sections. Or if you needed both to appear, for example on the front-page, you could use <code><txp:if_section name=”“></txp:if_section></code> and include both forms. You would need to maintain the forms of course as you add or remove sections but after the initial creation that wouldn’t be a big job methinks. Don’t know if that helps. You would need to be on TXP 4.0.2 for this to work.
Last edited by thebombsite (2005-11-13 19:48:14)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
#5 2005-11-14 03:58:58
- sersam
- New Member
- Registered: 2005-03-08
- Posts: 6
Re: filter a section_list output with substring?
Thank you! I think I’ll do it that way.
Some add-ons:
all this code
<code><txp:if section name=“section-en1,section-en2,section-en3”>
something…
<txp:else />
something…
</txp:if_section></code>
can be used as a form, so I can do a form “main_menu” and call this form from pages (and have to update sections names in one place only)
Can I define some string (section-en1,section-en2,section-en3) as “include” and call them from txp tags? (<code><txp:if section name=“include here”></code>)
<code><txp:output_form form=“english_names” /></code> doesn’t work in this case
Last edited by sersam (2005-11-14 05:41:32)
Offline
Re: filter a section_list output with substring?
Nice mod to do it all in a form. :)
I think that last bit might be one too many shortcuts. ;) I’ll have a look at something on my test site and post back if I can get anything to work.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline