webteam has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to exclude pages showing up from the navigation which is using the code below:
<server language="perl"> print "<div id=\"maincontent\">"; #<!-- LEFT --> print"<div id=\"left\">"; if ($item{itemtypeid} =~ '2572100') { print qq(<span class="sectionBack">&#60; <a href="/">Home</a></span>); print "<ul class=\"sectionNav\">\n"; print str_links(undef, '<li><a href=$url>$name</a></li>\n', 1, 'order' +, 'sortnumeric'); print "</ul>\n"; } else { my $sectionurl = "/" . substr(str_primaryattachpoint(), 1, index(str_p +rimaryattachpoint(), '/', 1)); my $sectionurl2 = str_primaryattachpoint(); my $sectionurl3 = str_primaryattachpoint($sectionurl2); my %section = getitem($sectionurl3, 0); print "<div id=\"leftnav\">"; my $parentlink = str_primaryattachpoint(); my $linkslist = str_links($parentlink, '$path,$name,$itemid:', 1, 'ord +er', 'sortnumeric'); my @topvariables = split(/:/, $linkslist); my $count = @topvariables; my $int = '0'; while ($int < $count) { foreach my $topvariables (@topvariables) { (my $link, my $title, my $id) = split(/,/, $topvariables); $topvariables[$int] = ([$link, $title, $id]); $int++; } } my $parentslink = str_previousbranch(); my $int2 = '0'; print "<ul class=\"sectionNav\">\n"; foreach (@topvariables) { #print $topvariables[$int2][2]. "<br>"; #print $item{itemid} . "<br>"; if ($topvariables[$int2][2]=~$item{itemid}) { print "<li><a class=\"currentpage\" href=\"$topvariables[$int2][0]\">$ +topvariables[$int2][1]</a>\n"; print "<ul class=\"submenu\">\n"; print str_links($topvariables[$int2][0], '<li class=\"nav2\"><a href=\ +"$path\" class=\"submenu\">$name</a></li>\n', 1, 'order', 'sortnumeri +c'); print "</ul></li>\n"; } else { print "<li><a href=$topvariables[$int2][0]>$topvariables[$int2][1]</a> +</li>\n"; print "<ul style='display:none;'>\n"; print str_links($topvariables[$int2][0], '<li class=\"nav2\"><a href=$ +url>$name</a></li>\n', 1, 'order', 'sortnumeric'); print "</ul></li>\n"; } $int2++; } print "</ul>\n"; } </server>
Could anyone please help me how to do this? Many thanks!

Replies are listed 'Best First'.
Re: Excluding pages from the navigation
by Unforgiven (Hermit) on Oct 29, 2009 at 12:56 UTC

    It would very much help if you'd wrap your code in <code> tags:

    <code>
    # Code goes here
    </code>
      Thank you so much, I have placed a <code> tag in there. Basically the script below is used in MediaSurface content management system.
      <server language="perl"> print "<div id=\"maincontent\">"; #<!-- LEFT --> print"<div id=\"left\">"; <code> if ($item{itemtypeid} =~ '2572100') { print qq(<span class="sectionBack">&#60; <a href="/">Home</a></span>); print "<ul class=\"sectionNav\">\n"; print str_links(undef, '<li><a href=$url>$name</a></li>\n', 1, 'order' +, 'sortnumeric'); print "</ul>\n"; } else { my $sectionurl = "/" . substr(str_primaryattachpoint(), 1, index(str_p +rimaryattachpoint(), '/', 1)); my $sectionurl2 = str_primaryattachpoint(); my $sectionurl3 = str_primaryattachpoint($sectionurl2); my %section = getitem($sectionurl3, 0); print "<div id=\"leftnav\">"; my $parentlink = str_primaryattachpoint(); my $linkslist = str_links($parentlink, '$path,$name,$itemid:', 1, 'ord +er', 'sortnumeric'); my @topvariables = split(/:/, $linkslist); my $count = @topvariables; my $int = '0'; while ($int < $count) { foreach my $topvariables (@topvariables) { (my $link, my $title, my $id) = split(/,/, $topvariables); $topvariables[$int] = ([$link, $title, $id]); $int++; } } my $parentslink = str_previousbranch(); my $int2 = '0'; print "<ul class=\"sectionNav\">\n"; foreach (@topvariables) { #print $topvariables[$int2][2]. "<br>"; #print $item{itemid} . "<br>"; if ($topvariables[$int2][2]=~$item{itemid}) { print "<li><a class=\"currentpage\" href=\"$topvariables[$int2][0]\">$ +topvariables[$int2][1]</a>\n"; print "<ul class=\"submenu\">\n"; print str_links($topvariables[$int2][0], '<li class=\"nav2\"><a href=\ +"$path\" class=\"submenu\">$name</a></li>\n', 1, 'order', 'sortnumeri +c'); print "</ul></li>\n"; } else { print "<li><a href=$topvariables[$int2][0]>$topvariables[$int2][1]</a> +</li>\n"; print "<ul style='display:none;'>\n"; print str_links($topvariables[$int2][0], '<li class=\"nav2\"><a href=$ +url>$name</a></li>\n', 1, 'order', 'sortnumeric'); print "</ul></li>\n"; } $int2++; } <code> print "</ul>\n"; } </server>

        Unforgiven told you how to use code tags, your closing code tag should be </code> and not <code>, for some reason you aren't placing these tags prior to the start of the code, and after the end.

        The reason for previewing before posting is to check your post format and content. Also there are links provided to How do I post a question effectively? and Writeup Formatting Tips, it would be wise to read these. Finally you could have simply edited your first post, adding code tags, rather than posting it all again.

Re: Excluding pages from the navigation
by talexb (Chancellor) on Oct 29, 2009 at 18:30 UTC

    Instead of going through this somewhat voluminous example, I'll just point out the excellent module Template Toolkit which should allow you to separate the logic from the presentation.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      Dear All, Thank you very much for your help and advice. Unfortunately there is no hope for us to upgrade MediaSurface for another year or so and we don’t have a Perl developer either to help us out. I have solved this issue with a very crude, hard-coded solution. Thank you again for you time.