1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Making "self-links" turn themselves off in the navbar using SSI

Discussion in 'Software' started by pho, 4 Aug 2003.

  1. pho

    pho What's a Dremel?

    Joined:
    24 May 2003
    Posts:
    69
    Likes Received:
    0
    This thread describes how to make "self-links" in the navbar turn themselves off using CSS. I recently figured out how to do this with SSI; SSI has one great advantage over CSS: it's server-side, meaning that it will display the same result in a text-only browser and a visual one (MSIE, Opera etc.). The problem with CSS, you see, is that it is done with visibility, meaning that both the link and the "fake" non-link text will display in text-only browsers, since they don't handle CSS. Needless to say, that is ugly. Onto the SSI magic:

    Each page must have an SSI directive at the very top in the form of:

    Code:
    <!--#set var="page" value="page01" -->
    You may call the 'var' value whatever you like, but if you choose to call it something else than "page", remember to use the same variable name in the navbar.shtml file. I go with 'page' for 'var' and the actual filename, minus the extension (.shtml) for the 'value' value. Now, the navbar.shtml that you include with SSI (<!--#include file="navbar.shtml">) will look roughly like this:

    Code:
    <!--#if expr="$page != page01" --><a href="page01.shtml"><!--#endif -->Page 01<!--#if expr="$page != page01" --></a><!--#endif --> -
    <!--#if expr="$page != page02" --><a href="page02.shtml"><!--#endif -->Page 02<!--#if expr="$page != page02" --></a><!--#endif --> -
    <!--#if expr="$page != page03" --><a href="page03.shtml"><!--#endif -->Page 03<!--#if expr="$page != page03" --></a><!--#endif -->
    When the server parses this file (after first incluing it), it looks for the <!--#set var="page" value="page01" --> you set for the page. If the value is not page01, it will display the link. If the page is page01, it will silently remove the anchor tag altogether.

    Linkage:

    - My site
     
    Last edited: 4 Aug 2003
  2. webchimp

    webchimp What's a Dremel?

    Joined:
    9 Oct 2002
    Posts:
    504
    Likes Received:
    1
    Could I make one suggestion.

    I don't actually use PHP, but I can sort of read it. Instead of breaking up the code into little bits you could build the whole thing into a loop. I can't write it in PHP, but here it is in ASP, perhaps you can read it and convert it to PHP:


    This is the value that sets the current page, equivalent to
    <!--#set var="page" value="page01" -->:

    <%
    varCurrentPage = "Page3"
    %>




    This block replaces your series of If-Thens:

    <%
    varAllPages = ("Page1,Page2,Page3,Page4,Page5,Page6,Page7")
    varPageArray = Split(varAllPages, ",")

    For i = 0 to Ubound(varPageArray)
    If varCurrentPage = varPageArray(i) Then
    Response.Write(varPageArray(i) & "&nbsp;&nbsp;")
    Else
    Response.Write("<a href=""" & varPageArray(i) & ".htm"">" & varPageArray(i) & "</a>&nbsp;&nbsp;")
    End If
    Next
    %>

    varAllPages would be all the page names in the site, it will make a link out of each on that isn't the current page name. I believe "Response.Write" is "echo" in PHP, but I have nio idea about loops and arrays.
     
  3. pho

    pho What's a Dremel?

    Joined:
    24 May 2003
    Posts:
    69
    Likes Received:
    0
    I don't know any PHP or ASP, but thanks for your post. I'll certainly look into it if/when I have learned PHP/ASP.
     

Share This Page