Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-12-05 14:30:00

jpsaenz
New Member
Registered: 2013-11-21
Posts: 5

Menu building whit <txp:section_list> and External-Link

Hello,

I’m trying to add a (external) link to my menu. At the moment my menu is constructed as follows:

<txp:section_list default_title=’<txp:text item=“home” />’ include_default=“0” sections=“intern1,intern2,intern3,intern4,intern5” wraptag=“ul” break=”“>
[…]

What I want to do is to incorporate an external link between “intern3” and “intern4” with which it is called [extern] so that the finished menu looks like this:

intern1 | intern2 | intern3 | extern | Intern4 | intern5

It’s possible?

Thank you (and sorry for my poor english!)

Juan Pablo

Offline

#2 2016-12-05 14:53:00

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,795
Website GitHub

Re: Menu building whit <txp:section_list> and External-Link

jpsaenz wrote #303166:

I’m trying to add a (external) link to my menu… It’s possible?

Everything’s possible ;-) But in this case it’s not intuitive because <txp:if_section> returns the current section you’re browsing, not the one inside the <txp:section_list> loop.

So to do it without PHP you could make your own variable containing the current section, like this:

<txp:section_list
   default_title='<txp:text item="home" />'
   include_default="0"
   sections="intern1, intern2, intern3, intern4, intern5"
   wraptag="ul"
   break="|">
   <txp:section title="1" />
   <txp:variable name="this_section"><txp:section /></txp:variable>
   <txp:if_variable name="this_section" value="intern3">
      | <a href="http://example.org/my/link">extern</a>
   </txp:if_variable>
</txp:section_list>

Hope that helps.

Last edited by Bloke (2016-12-05 14:55:34)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2016-12-05 15:10:19

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Menu building whit <txp:section_list> and External-Link

Another alternative using rah_replace:

<txp:section_list default_title='<txp:text item="home" />' include_default=“0” sections=“intern1,intern2,intern3,extern,intern4,intern5” wraptag="ul" break="">
  <li<txp:if_section name='<txp:section />'> class="active"</txp:if_section>>
    <a itemprop="url" href="<txp:rah_replace from="http://[yourdomain.com]/[extern]/" to="http://[yourtargetdomain.com]/"><txp:section url="1" /></txp:rah_replace>">
      <txp:section title="1" />
    </a>
  </li>
</txp:section_list>

You can see it in action here – the Textpattern link.

Offline

#4 2016-12-05 17:02:55

jpsaenz
New Member
Registered: 2013-11-21
Posts: 5

Re: Menu building whit <txp:section_list> and External-Link

Bloke wrote #303169:

Everything’s possible ;-) But in this case it’s not intuitive because <txp:if_section> returns the current section you’re browsing, not the one inside the <txp:section_list> loop.

So to do it without PHP you could make your own variable containing the current section, like this:

<txp:section_list...

Hope that helps.

Thanks, that works… but it duplicate the menu and break the order of the items:

click for screenshot

this is my complete Sourcecode whit your extra-lines:

<!-- BEGINN -->
    <nav role="navigation">
    <h1><txp:text item="navigation" /></h1>
    <txp:section_list default_title='<txp:text item="home" />' include_default="0" sections="home,produkte,ihreanfrage,druckshop,die-stories,downloads-hilfe,foto-videogalerie" 
	wraptag="ul" 
	break="">
<!--NEWLINES-->
<txp:section title="1" /><txp:variable name="this_section"><txp:section /></txp:variable>
<txp:if_variable name="this_section" value="ihreanfrage">| <a href="http://www.coloraprint.de/">Coloraprint</a></txp:if_variable>
<!--//NEWLINES-->
   <li<txp:if_section name='<txp:section />'><txp:if_search><txp:else /><txp:if_category><txp:else /><txp:if_author><txp:else /> class="active"</txp:if_author></txp:if_category></txp:if_search></txp:if_section>>
   <txp:section title="1" link="1" />
   </li> 
    </txp:section_list>
  </nav>
<!-- END -->

What did I do wrong?

Thanks!

Last edited by jpsaenz (2016-12-05 17:10:16)

Offline

#5 2016-12-05 17:13:20

jpsaenz
New Member
Registered: 2013-11-21
Posts: 5

Re: Menu building whit <txp:section_list> and External-Link

michaelkpate wrote #303170:

Another alternative using rah_replace:

<txp:section_list default_title='<txp:text item="home" />' include_default=“0” sections=“intern1,intern2,intern3,extern,intern4,intern5” wraptag="ul" break="">...

You can see it in action here – the Textpattern link.

Thank you very much, but it did not work for me…

Offline

#6 2016-12-05 17:39:48

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Menu building whit <txp:section_list> and External-Link

Try this. I think you were evaluating the variable in the wrong place.

<!-- BEGINN -->
    <nav role="navigation">
    <h1><txp:text item="navigation" /></h1>
    <txp:section_list default_title='<txp:text item="home" />' include_default="0" sections="home,produkte,ihreanfrage,druckshop,die-stories,downloads-hilfe,foto-videogalerie" 
	wraptag="ul" 
	break="">
<!--NEWLINE-->
<txp:variable name="this_section"><txp:section /></txp:variable>
<!--//NEWLINE-->
   <li<txp:if_section name='<txp:section />'><txp:if_search><txp:else /><txp:if_category><txp:else /><txp:if_author><txp:else /> class="active"</txp:if_author></txp:if_category></txp:if_search></txp:if_section>>
   <!--NEWLINE-->
     <txp:if_variable name="this_section" value="ihreanfrage"><a href="http://www.coloraprint.de/">Coloraprint</a><txp:else /><txp:section title="1" link="1" /></txp:if_variable>
     <!--NEWLINE-->
   </li> 
    </txp:section_list>
  </nav>
<!-- END -->

Last edited by michaelkpate (2016-12-05 18:06:21)

Offline

#7 2016-12-05 18:01:36

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Menu building whit <txp:section_list> and External-Link

A somewhat simpler re-edit

<!-- BEGINN -->
<nav role="navigation">
  <h1><txp:text item="navigation" /></h1>
  <txp:section_list default_title='<txp:text item="home" />' include_default="0" sections="home,produkte,ihreanfrage,druckshop,die-stories,downloads-hilfe,foto-videogalerie" 
	wraptag="ul" 
	break="">
    <!-- only apply class="active" if you are on a non-search non-author non-category page -->
    <li<txp:if_section name='<txp:section />'><txp:if_search><txp:else /><txp:if_category><txp:else /><txp:if_author><txp:else /> class="active"</txp:if_author></txp:if_category></txp:if_search></txp:if_section>>
      <!-- store the value of the current section from section_list in the variable this_section -->
      <txp:variable name="this_section"><txp:section /></txp:variable>
      <!-- output custom output if the current section is "ihreanfrage" -->
      <txp:if_variable name="this_section" value="ihreanfrage">
        <a href="http://www.coloraprint.de/">Coloraprint</a>
      <txp:else />
        <txp:section title="1" link="1" />
      </txp:if_variable>
    </li> 
  </txp:section_list>
</nav>

Offline

#8 2016-12-05 18:02:18

jpsaenz
New Member
Registered: 2013-11-21
Posts: 5

Re: Menu building whit <txp:section_list> and External-Link

michaelkpate wrote #303181:

Try this. I think you were evaluating the variable in the wrong place.

It works! Thankyou very much!

Saludos!

Offline

Board footer

Powered by FluxBB