Page

11.3.4- Using the Content Linker and Control Structures to Display Only Appropriate Links

Created by Brendan Doss.
Last Updated by Jim Minatel.  

PublicCategorized as 11. Active Server Pages Components.

Not yet tagged
<< 11.3.3- Adding Descriptions and Previous to Our LinkChapter1111.3.5- Using the Content Linker with Home and End Hyperlinks >>

Using the Content Linker and Control Structures to Display Only Appropriate Links

By now your hyperlinks for touring the on-line clothier are efficient for several reasons:

 

  • The user is guided through the pages of the tour in the order of your design.
  • The viewer gets a description of the next and previous pages, which assist his or her orientation.

 

However, there remain some rough edges. For example, the first page should not contain a "Previous link" and the last should not contain a "Next Link." So we need to improve the Navigation file so that it can sense if it is on the first page (don't print previous link) or on the last page (don't print Next link).

Try It Out – Using Appropriate Links

In this example, we will perform a test to see if a next link exists, i.e. if there is a line following the current line in the Index file. Only if there is a next link will we display the Next hyperlink on the page. We will also test for a previous line to determine whether to print the previous link.

 

Again, you may want to save the existing version of CL-Navigation.asp as CL-Navigation02.asp so you can review the exact syntax of the second content linker Try-It-Out. If you are downloading files from Wrox, the file below will be CL-Navigator03.asp, rename it to CL-Navigation.asp so that you don't need to change all of your links within each product page.

 

1.    Open the file CL_Navigation.asp and amend it to the following, then save.

 

<%

Response.Write "<HR>"

Dim MyPageNext

Dim MyPagePreviousious

Dim MyDescriptNext

Dim MyDescriptPrev

Dim MyListCount

Dim MyListIndex

Dim objNL

Set objNL = Server.Createobject("MSWC.NextLink")

MyPageNext = objNL.GetNextURL("CL-NewProductsTour.txt")

MyPagePrevious = objNL.GetPreviousURL("CL-NewProductsTour.txt")

MyDescriptNext = objNL.GetNextDescription("CL-NewProductsTour.txt")

MyDescriptPrevious = objNL.GetPreviousDescription("CL-NewProductsTour.txt")

MyListCount = objNL.GetListCount("CL-NewProductsTour.txt")

MyListIndex = objNL.GetListIndex("CL-NewProductsTour.txt")

 

If MyListIndex > 1 Then

Response.Write "Back: <A href='" & MyPagePrevious & "'>" &_

MyDescriptPrevious & "</A> <BR>"

End If

 

If MyListIndex < MyListCount Then

Response.Write "Next: <A href='" & MyPageNext & "'>" &_

MyDescriptNext & "</A> <BR>"

End If

%>

 

Chapter11_image007

 

 

Chapter11_image008

 

Chapter11_image009

How It Works

The whole thing works because we are able to use our NextLink object to obtain the following information from the index file:

 

  • The number of URL lines in the index file
  • The number of the URL that is currently shown

The first difference from previous CL-Navigation files is that we create two more variables:

 

Dim MyListCount

Dim MyListIndex

 

We fill the first using the method objNL.GetListCount which returns a number that ASP obtains by counting the lines in the Index file:

 

MyListCount = objNL.GetListCount("CL-NewProductsTour.txt")

 

Note that the Count will be the same for all of the pages.

 

Then, objNL.GetListIndex returns the number of the URL line for the current page:

 

MyListIndex = objNL.GetListIndex("CL-NewProductsTour.txt")

 

For example, in the file CL-Tie.asp, this line looks up CL-Tie.asp in the index file, CL-NewProductsTour.txt, and returns the value 3 (because CL-Tie.asp is the third on the list).

 

Armed with these values we can use logic to say that if we are not on the first page (that is, MyListIndex is greater than 1), then we should show a Previous hyperlink:

 

If MyListIndex > 1 Then

Response.Write "Back: <A href='" & MyPagePrevious & "'>" &_

MyDescriptPrevious & "</A> <BR>"

End If

 

We can also say that, provided our current URL number is less than the total number of URLs (that is, MyListIndex is less then MyListCount), then we should show a Next hyperlink:

 

If MyListIndex < MyListCount Then

Response.Write "Next: <A href='" & MyPageNext & "'>" &_

MyDescriptNext & "</A> <BR>"

End If

 

If the Webmaster changed the order of these pages in the index file the pages would automatically compensate their Next/Previous appearance and descriptions, all from the magic of the Content Linker.

<< 11.3.3- Adding Descriptions and Previous to Our LinkChapter1111.3.5- Using the Content Linker with Home and End Hyperlinks >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |