
pageWHIFF provides a configuration template file format which may be used to specify how to build an application using other applications, middlewares, environment variables and other parameters. These configuration files usually have the extension
env
page parameters
page components
page text
get-env
id/get-id
get-cgi
include
include with no arguments
include with a single "page" argument
include with named sections
include with environment modifications
use-include
reuse
use
FILENAME.whiff and WHIFF directories are often configured to interpret
the templates.
Configuration templates are only one form of template which may be used with WHIFF -- WHIFF may also be used with other template formats. For example a WHIFF page may be implemented using the very terse, fast, popular, and convenient Mako template format. Please see the Standard Middleware documentation for discussion of the standard embedding of Mako within WHIFF.
The following sections describes how to build a WHIFF configuration template and the configuration directives which may occur in templates.
A configuration template file defines a WSGI application to produce a stream of bytes from a WSGI environment dictionary and (optionally) additional external parameters.
Configuration templates are primarily designed as a convenient way to wire together applications, middlewares, resources, and environment parameters.
page syntax
page exampleinclude
{{include "whiff_middleware/Noop"}}
{{/include}} constitutes a page.
| whiff source | generated page | formatted output |
|
temp content
|
||
page discussionIn the example above the "Noop" no-operation middleware wraps the example page in a page component. This allows the mini-page to parse inside the larger page that generated the document you are reading.
env environment directive for a page
allows a page to specify that entries be added or overwritten
in the WSGI environment dictionary.
env syntax


env exampleNoop middleware specifies
a first name, last name and address in the environment modification
and then uses these values in the body of the page.
| whiff source | generated page | formatted output |
|
temp content
|
||
env discussionpage parameters syntax


page parameters exampleNoop specifies a
default value of Greetings Earthling for the page argument named
GREETING and also provides a default value of Human
for the form input argument named SPECIES.
| whiff source | generated page | formatted output |
|
temp content
|
||
page parameters discussioncgi-default HTML form input argument defaults.
If the page is invoked with an explicit GREETING argument
provided the provided value is used and the default is ignored.
Similarly if the page is invoked with an environment that defines
the CGI form argument SPECIES, the default value
provided by the page is not used.
If there is a cgi-prefix in effect the cgi-default
name will be adjusted with the prefix.
In the example given above if the prefix PREFIX_
is in effect then the global form argument name associated with the
cgi-default statement above is PREFIX_SPECIES.
page components syntax
page components exampleget-env component.
| whiff source | generated page | formatted output |
|
temp content
|
||
page components discussion}$} and {${
are replaced by
}} and {{ respectively.
page text syntax
page text example| whiff source | generated page | formatted output |
|
temp content
|
||
page text discussionget-env construct allows a page to extract
an entry from it's environment using the exact name of the entry
get-id and get-cgi
use the name relative to the current cgi-prefix
as described below.
get-env syntax
PAGE may be used to
specify a default value to use if the environment contains
no such entry.
indexed name syntax allows get-env
directives to extract subcomponents of structures in the environment,
such as named entries in dictionaries and indexed locations in lists.
get-env exampleget-env are shown above.
The following is a more sophisticated example
| whiff source | generated page | formatted output |
|
temp content
|
||
get-env discussionkids. The whiff_middleware/repeat middleware
iterates over the members of the list and places each in turn into
the environment entry kid. The page argument
to whiff_middleware/repeat formats each of the entries
using get-env directives and indexed names.
get-env construct only.
id and get-id directives allow a page
component to get names and environment entries relative to the
current CGI-prefix for the page.
id/get-id syntax
PAGE may be used to
specify a default value to use if the environment contains
no such entry.
id/get-id example| whiff source | generated page | formatted output |
|
temp content
|
||
id/get-id discussionwhiff.cgi_prefix
in different locations we can get the same page fragment
{{id name/}}={{get-id name/}} was born in {{id from/}}={{get-id from/}}
id directive extracts a name relative to the current prefix
and the get-id directive extracts a value in the environment
associated with the name.
get-cgi construct extracts a value submitted via a form
input element. The get-cgi construct always extracts a name
adjusted by the current cgi-prefix if set.
get-cgi syntax
get-cgi example| whiff source | generated page | formatted output |
|
temp content
|
||
get-cgi discussionUSER_NAME provided
as a form argument. If no such form argument is available the
page uses default value NOBODY
defined by the cgi-default directive.
The environment directive
{{env whiff.parse_cgi: true /}}
get-cgi construct will raise an exception if the
cgi parameters have been not been parsed.
include directive allows a template
to use and configure another application
and insert the output of that application in the
byte stream.
include syntax

include example| whiff source | generated page | formatted output |
|
temp content
|
||
include discussioninclude directive uses the
whiff_middleware/quoteHtml middleware to "quote" the angle
brackets in an HTML text fragment so that the HTML tags are visible when
the text is formatted.
This example sends a single page argument to the
quoteHtml middleware.
There are several other ways that an include construct can
parameterize an application or middleware as described below.
include directive.
include with no arguments syntax
{{include "PATH/TO/APPLICATION"/}}
/}} -- it's required.
include with no arguments example| whiff source | generated page | formatted output |
|
temp content
|
||
include with no arguments discussionwhiff_middleware/debugDump application to
show the environment for the page. The debugDump application
requires no arguments.
include with a single "page" argument syntax
{{include "PATH/TO/APPLICATION"}} THE SINGLE PAGE ARGUMENT {{/include}}
{{use NAME_OF_ARGUMENT/}} (or similar)
with an explicit argument name in order to use their arguments.
For this reason a single page
argument is always named simply page automatically
and the middleware may refer to the argument using {{use page/}}
(or similar).
include with a single "page" argument example| whiff source | generated page | formatted output |
|
temp content
|
||
include with a single "page" argument discussionwhiff_middleware/absPath middleware translates a relative
URL to an absolute URL path relative to the current server.
The whiff_middleware/absPath middleware only requires one argument.
include may include using specifications
to pass more than one explicitly named arguments.
include with named sections syntax
include with named sections exampleusing directive
inside a include
we introduce the following simple external middleware configuration
stock defined in the file stock.whiff with content as follows
{{comment: this is the content of INSTALL/doc/docroot/stock.whiff }}
{{require company/}}
{{require ticker/}}
{{require description/}}
<table border>
<tr>
<th> {{use ticker/}} </th> <th> {{use company/}} </th>
</tr>
<tr>
<td colspan="2">
{{use description/}}
</td>
</tr>
</table>
stock middleware formats a simple table containing information about a company
using parameters for the company information.
The following page fragment uses the stock middleware three times with the
aid of the using directive to define the named parameters.
| whiff source | generated page | formatted output |
|
temp content
|
||
include with named sections discussionstock middleware required three arguments. Instead we use the
using directive to define the named parameters to the
stock middleware.
include may pass a modified environment to an included application
or middleware in three ways that are directly supported by configuration syntax (and
external middlewares may implement other ways as well).
include with environment modifications syntax
ENV PAIRS above may modify globally named
environment parameters passed to an application or middleware.
set-id directive may add or override
environment parameters named relative to the current CGI prefix.
set-cgi directive may add or override
a form input value named relative to the current CGI prefix.
include with environment modifications exampleinclude
directive we introduce the application intro configured using the file
intro.whiff containing the following content.
The operating system is: {{get-env OS/}}. <br>
The user is: {{id USER/}}={{get-cgi USER/}}. <br>
The filename is: {{id FILENAME/}}={{get-id FILENAME/}}. <br>
intro application is contrived to simply display some
information about its environment.
The following page fragment uses the intro application twice,
providing different CGI prefix specifications.
| whiff source | generated page | formatted output |
|
temp content
|
||
set-id directive expects
a JSON value -- which is why the filenames are surrounded by quotation marks.
include with environment modifications discussionuse-include directive is a short-hand convenience
which passes an external application
as an argument to a used application without modifying the passed value.
use-include syntax
use-include examplecyan.txt
containing information about Cyanotech corporation. We
use the use-include directive to pass the file
cyan.txt as the description to the stock
middleware discussed earlier.
| whiff source | generated page | formatted output |
|
temp content
|
||
use-include discussionuse-include directive
provides a terse syntax to make simple wiring simple to write.
reuse directive is a short-hand convenience
which passes an argument of
the current page to a used application without modifying the argument.
reuse syntax
reuse exampleinformation to the stock
middleware as the description using.
| whiff source | generated page | formatted output |
|
temp content
|
||
reuse discussionreuse directive
provides a terse syntax to make simple wiring simple to write.
use directive inserts the value of
a page argument.
use syntax
use directive is very similar
to the include directive, except that use
uses an internal argument to the page whereas the
include directive uses an external application
or middleware.
use exampledisplay
for formatting a table. The page content uses the middleware twice to format
verses from Lewis Carrolls "Mad Gardener's Song".
| whiff source | generated page | formatted output |
|
temp content
|
||
use discussiondisplay middleware and the main page in the
example above demonstrate the use of the use
directive. The display middleware use shows the single
argument form and the use inside the display middleware
shows the no-argument form of the directive.