PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: /Syntax[Next]: /Validate
\ -> PPWIZARD Command Line -> Switches -> /Template

Switch /Template:TemplateFile

This is a PPWIZARD command line switch.

Normally PPWIZARD begins by reading from the input file identified on the command line. This switch modifies this behavior so that the identified template (or "skeleton") file is read instead. The value of the data file can be obtained from the "<?TemplateDataFile>" variable.

If you have a set of similar pages you can set up a single template file which describes the common attributes (header/footer, look and feel, background colors etc) and many "data" files each of which describes the differences (such as the title and page text).

The template file does not automatically load or process the "data" file in any way, it is up to you to perform the appropriate action which would usually involve including the "data" file using:

Note that there is now a "sites" addon for PPWIZARD that could be very useful when using the template switch as it could be used to configure page titles or any other details you wish kept separate from the page "body" (example below).

Example #1

In this example the data file defines the body of the HTML page as well as its "title" (the filename). I use this approach when importing from CSV or similar databases, the filename of the file doubles as the title of the page.

A typical page might look like:

<p>Para 1.
<p>Para 2.

A typical template file might look like:

;--- Start HTML ---
<html>
<head>
   ;--- Name of "data" file is the pages title ---
   <title><?TemplateDataFile:name,withoutextn></title>
</head>
<body>

;--- Include common definitions ---
#include "common.ih"

;--- Include body ---
#include "<?TemplateDataFile>"

;--- End Html ---
<hr size=1>
<center>
   <?OutputFile:name>
   <br>
   <?CompileTime>
</center>
</body>
</html>

To make the test page (test.txt) you could use:

PPWIZARD test*.TXT /template:common.tem /Output:out\*.html /DependsOn:out\DependsOn\*.dep

Example #2

In this example the data file defines the body of the HTML page as well as a number of other values including the page "title".

A typical page might look like:

;--- Define page attributes ----
#define PageTitle       The pages title
#define MetaKeywords    keyword1, keyword2
#define MetaDescription Description shown in search engines etc.

;--- Define the page contents ----
#( '<?NewLine>'
   ;--- This "body" macro expanded by template ---
   #define PageContent

   ;--- Content follows ---
   <p>Para 1.
   <p>Para 2.
#)

A typical template file might look like:

;--- Include any common definitions ---
#include "common.ih"

;--- Include data file (being merged with template) ---
#include "<?TemplateDataFile>"

;--- Start HTML ---
<html>
<head>
   ;--- Set page title ---
   <title><$PageTitle></title>

   ;--- Output stuff for search engines ---
   <META name="description" content="<$MetaDescription>">
   <META name="keywords" content="<$MetaKeywords>">
</head>
<body>

;--- All pages have "h1" of "PageTitle" ---
<h1><$PageTitle></h1>

;--- The data file defined the body ---
<$PageContent>

;--- End Html (footer etc) ---
<hr size=1>
<center>
   <?OutputFile:name>
   <br>
   <?CompileTime>
</center>
</body>
</html>

Example #3 - Use SITES add-on

This example shows how the sites add-on could be used. In real life I'd conditionally include navigation buttons (so as not to produce blank entries appear) and I'd move more into the common header file "common.ih".

A typical page might look like (perhaps called "page1.dat"):

<p>This is the first paragraph of the first page of the site.

<p>Para2

A typical template file might look like:

;--- Include common header
#include "common.ih"

;--- Include SITES PPWIZARD add-on ---
#include "sites.ih"

;--- Define this site (only has 3 pages) ---
<$Site "MySite">
   <$Page "page1"  TITLE="First page of site">
   <$Page "page2"  TITLE="Middle page of site">
   <$Page "page3"  TITLE="Last page of site">
<$/Site>

;--- Point to this pages details ---
<$PageGet Result="PageThis">
<$PageGet "<??PageThis_PAGEPREV>"  RESULT="PagePrev"  DIE="N">
<$PageGet "<??PageThis_PAGENEXT>"  RESULT="PageNext"  DIE="N">
<$PageGet "<??PageThis_PAGEFIRST>" RESULT="PageFirst" DIE="N">
<$PageGet "<??PageThis_PAGELAST>"  RESULT="PageLast"  DIE="N">

;--- Some simple definitions ---
#define COLOR_BG   white
#define H1         <center><h1>{$Text}</h1></center>

;--- My very basic navigation bar (look and feel etc) ---
#( '<?NewLine>'
   #define SiteNavStart
   <div class="SiteNav">
   <table border=1>
   <tr>
#)
#( '<?NewLine>'
   #define SiteNavItem
   <td>
   #if Page{$#1}_RC <> '' | Page{$#1}_PAGEKEY = PageThis_PAGEKEY
       ;--- Details unavailable or point to "self" ---
       <font color="<$COLOR_BG>">{$#1}</font>   ;;Invisible but stays same size!
   #elseif
       ;--- Have details ---
       <a href="<??Page{$#1}_HTMLNAME>" title="<??Page{$#1}_HTMLNAME> - <??Page{$#1}_TITLE>">{$#1}</a>
   #endif
   </td>
#)
#( '<?NewLine>'
   #define SiteNavEnd
   </tr>
   </table>
   </div>
#)

;--- Setup the Footer ---
#OnExit <?NewLine><?NewLine><$HtmlFooter>
#( '<?NewLine>'
   #define HtmlFooter

   ;--- The footer ---
   <p>
   <hr color=red size=1>
   <center>
       <??PageThis_HTMLNAME>
       <br>
       <?CompileTime>
   </center>
   </body>
   </html>
#)


;--- Start of HTML and set title ---
<html>
<head>
   <title><??PageThis_TITLE></title>
</head>

;--- Start of Body and navigation links ---
<body BGCOLOR="<$COLOR_BG>">
<center>
<$SiteNavStart>
   <$SiteNavItem "First">
   <$SiteNavItem "Prev">
   <$SiteNavItem "Next">
   <$SiteNavItem "Last">
<$SiteNavEnd>
Very primitive navigation bar (first 2 items blank)...
</center>

;--- Page always starts with a heading ---
<$H1 Text="<??PageThis_TITLE>">

;--- Include body ---
<?NewLine><?NewLine>
#include "<?TemplateDataFile>"

Alternative Methods

Using this switch is not the only way you can create your pages from templates. You could use #define and #include commands to define and include macros, a bit like the following:

;--- Load common definitions/macros ---
#include "Common.ih"

;--- Output the header (start html, title etc) ---
<$Header Title="My pages title">

;--- The body of your page ---
<p>Para 1.
<p>Para 2.

;--- Output the footer ---
<$Footer>

In the above example, "common.ih" does not generate anything but simply creates definitions for you to use. A supplementary or alternative approach is for it to create the start of the html and perhaps to generate the footer (see #OnExit). Your page might then look more like this:

;--- Load common definitions/macros ---
#define  PAGE_TITLE        My pages title
#define  META_DESCRIPTION  Free Windows software
#define  META_KEYWORDS     Keyword1, Keyword2
#include "Common.ih"

;--- The body of your page ---
<p>Para 1.
<p>Para 2.

Notice how in the above the #define command was used to pass information to the included header file (common.ih).

I actually use the above approaches for my pages and generally only use the /template switch when processing CSV or other databases to generate HTML pages.


email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: /Syntax[Next]: /Validate


PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am