[ The Sunny Spot ] WPP v2.10 - The Web Preprocessor
Author : Marco Lamberto
Preprocessed by WPP
   Index < Previous    Next >   

  Step 1: Yor first file [ ^ ]

Suppose you have a file p.html that you wish to generate throught wpp.
Make a 'raw/templates' directory with the command:
  mkdir -p raw/templates

Files in the raw directory are called raw files, files in the templates directory are called templates.
Enter into the raw directory and start writing a new file called p.raw

p.raw
@HEAD@
@TAIL@
$Date$
<HTML>
<HEAD>
<TITLE>Generated from p.raw</TITLE>
</HEAD>

<BODY>
<H1>Generated from p.raw</H1>
</BODY>
</HTML>

p.raw resemble a common html file except from the first three lines.
Generate the ../p.html file with the command
  wpp p.raw

Suppose you want to change the "Generated from p.raw" title it into "My First Page", you have to write it twice. You could use sed but if you don't know it or don't want to use it the best solution is to use wpp.

p.raw
@HEAD@
@TAIL@
$Date$
@TITLE=My First Page@
<HTML>
<HEAD>
<TITLE>@TITLE@</TITLE>
</HEAD>

<BODY>
<H1>@TITLE@</H1>
</BODY>
</HTML>

In the fourth line we have declared a simple variable called TITLE, so every time you want to change the title of p.raw you should edit it once.

  Step 2: Using templates [ ^ ]

You may need to write two or more file with common header and footer (except from title or something else).
By default WPP include a file templates/head.tmpl after the $Date$ tag and a templates/tail.tmpl at the end of file.
In the first step we have used the @HEAD@ and @TAIL@ directives in order to avoid to include them.
Now you can change p.raw and create templates/head.tmpl and templates/tail.tmpl.

p.raw
@TITLE=My First Page@
$Date$
This is an example page.
...
templates/head.tmpl
<HTML>
<HEAD>
<TITLE>@TITLE@</TITLE>
</HEAD>

<BODY>
<H1>@TITLE@</H1>

templates/tail.tmpl
Author: jack@hide
</BODY>
</HTML>
The template is simply an html fragment that may contain variables and if conditions, as you can do in a .raw file.
Including an html fragment is quite simple, write it into a file in the templates directory and call it fragment.tmpl (don't forget the .tmpl extension).
To include the template use the @INCLUDE fragment@ directive (here you must omit the templates directory and the .tmpl extension).
Into the templates directory you can create other directories, in order to include a file you simply use @INCLUDE dir/fragment@.

  Step 3: The config files and the conditional generation [ ^ ]

When wpp is started it first look into the raw directory for a file called 'config' (this is the default, you can specify a different file with the config file switch).
Here you can put common variables and use different config files for conditional generation of files.
In example you could create a file called ctest.raw:

ctest.raw
$Date$
...
@IF SHOW_IMAGES@
  <IMG SRC="images/ctest.gif">
@ENDIF@
...
Now write three config files:
  • config.common that contains common variables
  • config
  • config.noimg
The last two configs contains an @INCLUDECFG config.common@ directive and a variable declaration @SHOW_IMAGES=y@ in config.
Now if you run
  wpp -c=config.noimg ctest.raw
it generates ../ctest.html without images.
You can set the DEFAULT_OUTPUTDIR to something different from ".." (i.e. ../noimg.version/ into config.noimg) in order to create separate versions of ctest.html.

   ^ Top < Previous    Next >   
Marco (LM) Lamberto lm@geocities.com
Revised: 1998/09/23 11:26:51
http://www.geocities.com/Tokyo/1474/wpp/manual_3.html
Preprocessed by WPP Graphics by GIMP