6.11 Project

The project is to create a template for www.opensourcewebbook.com, where we put together all the pieces that we have discussed. The complete source can be found on this book's web site. Snippets are discussed later in this section.

The first source file to examine is the template file, oswb.wml . This file can be found online at either http://localhost/wml/oswb.wml or www.opensourcewebbook.com/wml/oswb.wml. The first thing to notice is that the template uses wml::std:: info . Some nifty information is included in the header using the <info> tag.

6.11.1 Defining New Tags

At the top of the template, two tags, link and red , are defined:

 <define-tag link whitespace=delete>  <preserve href>  <preserve text>  <set-var %attributes>  <a href="<get-var href>"><font color="#999966">           <b><get-var text></b></font></a>  <restore href>  <restore text>  </define-tag>  <define-tag red whitespace=delete endtag=required>  <font color="#FF0000"><b>%body</b></font>  </define-tag> 

This makes creating links and marking red text lead-pipe simple.

6.11.2 Varying the Title

The title tag is defined as:

 <title>Open Source Web Book  $(title)</title> 

When this template is used, we can say something like this:

 #use wml::oswb title="Errata" 

6.11.3 The Bread Crumb Trail

Here is the eperl code to generate the bread crumb trail. As we saw earlier, this is generated by giving the variable $(page) a value.

 <:      # grab the page information passed in      my $page_string = "$(page)";      # if the page info is not blank, process it      if ($page_string ne "") {          # first, print some red text          print "<font color=\"#FF0000\"><b>Page Path - </b></font>";          # split the line on the colon in case we are passing more          # than one piece of information as in:          # href1:text1:href2:text2:final text          # loop through, building the link          my @page = split(/:/, $page_string);          while (@page > 1) {              my $href="$(ROOT)" . shift(@page);              my $text = shift(@page);              print "<a href=\"$href\"><font color=\"#999966\">                             <b>$text</b></font></a> - ";          }          print "$page[0]";      }  :> 

6.11.4 The Left Rail

Several links make up the left rail of the page:

 <tr><td><link href="$(ROOT)/" text="Home"></td></tr>  <tr><td><link href="$(ROOT)/about/" text="About"></td></tr>  <tr><td><link href="$(ROOT)/foreword/" text="Foreword"></td></tr>  ... 

$(ROOT) is used here to make all the links relative to the desired directory /var/www/html .

6.11.5 The Right Rail ”Yes or No?

Two eperl sections in the template check the value of $(rightrail) , which determines whether there will be a right rail on the page. Some pages have a right rail that usually includes links to examples, but some do not. The first eperl block that checks this variable prints the width of a <td> tag. If the right rail is present, its width is 333 ; otherwise , its width is 550 :

 <:      my $rr = "$(rightrail)";      if ($rr eq "no") {          print "<td width=\"550\" valign=\"top\">\n";      } else {          print "<td width=\"333\" valign=\"top\">\n";      }  :> 

The next block checks to see whether the page has a right rail; if it does, it builds the HTML for the <td> tags:

 <:      my $rr = "$(rightrail)";      if ($rr ne "no") {          print "<td width=\"20\">&nbsp;</td>\n";          print "<td width=\"2\" bgcolor=\"#999966\">&nbsp;</td>\n";          print "<td width=\"15\">&nbsp;</td>\n";          print "<td width=\"180\" valign=\"top\"><<RIGHTRAIL>>&nbsp;                           </td>\n";      }  :> 

In the last <td> tag, there is a <<RIGHTRAIL>> . This is a diversion that will be defined later, in a page that has a right rail, such as /var/www/html/contents/wml/index.html .

6.11.6 Include PAGE_BODY

Somewhere in the middle of the file is the text <<PAGE_BODY>> . At this point all the things in this diversion are included. The last line of the template is ..PAGE_BODY>> , which says that all that follows (the stuff in the file that is using this template) is the text that is inserted into <<PAGE_BODY>> .

6.11.7 A Page without a Right Rail

First, a page that does not have a right rail: /var/www/html/wml/errata/index.wml . The first line of this page is:

 #use wml::oswb title="Errata" page="Errata" rightrail="no" 

This sets the title and page path (with no links, because there is only one thing in the string) and says "no" to the right rail. The rest of the file is the HTML that will be included in the template when it uses the diversion <<PAGE_BODY>> .

Try this yourself. First, build the HTML:

 $  wmk index.wml  wml -n -o index.html index.wml 

Then go to either http://localhost/errata/ or www.opensourcewebbook.com/errata/. The result can be seen in Figure 6.11. No right rail, as asked for.

Figure 6.11. Errata


6.11.8 A Page with a Right Rail

Now, a page with a right rail. One can be found in /var/www/html/contents/wml/index.wml . The first line is:

 #use wml::oswb title="Content  WML" page="/contents/:Contents:WML" 

This page has set the title and the bread crumb trail and has not assigned the rightrail variable, which means we will have a right rail (we could have also assigned it anything other than "no" to achieve this).

The stuff following this line is the HTML that will be in the middle of the page.

6.11.9 The RIGHTRAIL Section

We then see the line <divert RIGHTRAIL> , which begins the HTML that will be displayed in the right rail of the page. [9] It is a bunch of links to the examples in this chapter. The definition of this diversion continues until </divert> at the end of this file.

[9] We could have used the syntax ..RIGHTRAIL>> ... <<.. if we had wanted to.

Try this yourself. First, build the HTML:

 $  wmk index.wml  wml -n -o index.html index.wml 

Then go to http://localhost/contents/wml/ or www.opensourcewebbook.com/contents/wml/ (the first if you built it yourself, the latter if you are being lazy). The result can be seen in Figure 6.12.

Figure 6.12. The WML page ”right rail example


Open Source Development with Lamp
Open Source Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP
ISBN: 020177061X
EAN: 2147483647
Year: 2002
Pages: 136

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net