UHTML–Example

English Version

Other Sites:

uHTML–Logo
 

Rolling out identical data

The content of the <head> section usually remains widely unaltered across all HTML files of a website. The vantage of keeping the constant part in a separate file is obvious. What we need to do it like this with UHTML is to create an <include> tag that inserts the content of one file called head-data in several html files. We suppose that we have an include directory in our document root where we keep our overlapping chunks of HTML. Our UHTML file could then look like this:

index.uhtml
  
  <html>
    <head>
      <include file="/include/head-data">
      ...
    </head>
  ...
  </html>

The functionality of the <include> tag is an asset in many projects. Following the mentioned naming convention proposal the perl code is placed in a file named include.pm located in the subdirectory UHTML of the script directory. The file include.pm looks then like that:

include.pm
  
  use uHTML ;

  sub Include($) {
  my $Node = shift;
  $Node->map(join('',<FH>),'') 
    if $Node->Param('file') and
       open FH,$ENV{'DOCUMENT_ROOT'}.$Node->Param('file');
  }

  uHTML->registerTag('include',\&Include);

To link this small library into a website a cgi hook is needed. We place the necessary code in a file called hook.pl in the script directory:

hook.pl
  
  #!/usr/bin/perl

  use uHTML ;

  open FILE,"$ENV{'DOCUMENT_ROOT'}$ENV{'PATH_INFO'}" 
    or die "File: $ENV{'PATH_INFO'} not found";
  print "Content-type: text/html\n\n";
  print uHTML->recode(<FILE>);

To get the functionality “magically” into all *.uhtml files, we add some lines into the .htaccess file:

.htaccess
  
  RewriteEngine on
  RewriteRule ^(/?)(.*\.uhtml) $1cgi-bin/hook.pl/$2 [L,QSA]

This full working example shows just the basic integration of UHTML into a website. It do not show the use of variable parameters or request initialisation, but including any of this two is trivial.

divider


 
Valid HTML 4.01 Transitional CSS is valide!
uHTML–Logo

2008 All Rights Reserved Jorga Interactive | valid html 4.01 | valid css