No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Installation requires pip.

The Makefile performs a local pip install so ~/.local/bin needs to be added the path to run the examples after installing.

git clone
cd templatz
make install
cd tests


The usage string:

usage: templatz [-h] [-o OUT_DIR] [-c GLOBAL_CONFIG] [-d DEBUG] \
                    CONFIG_FILENAME [CONFIG_FILENAME ...]

See the tests/basic-index directory for example file layout.

Typical usage is

templatz -c site.cfg -o out index.cfg

or pages can also be built in one go,

templatz -c site.cfg -o out index.cfg page*.cfg


Multiple templates are assembled into a single file based on block specs in a config file. The placeholders in a template follow the ${} syntax described in PEP292.

However, there are a few modifications. When placeholders are replaced with values in templates for *.html, *.htm, or *.xml files, they are html escaped by default. This behavior can be changed as follows. If the config file contains

{ 'foo': 'R & D', 'filename': 'index.htm' }

then substitutions are as follows

${foo}  :  R & D
${!foo} :  R & D
${&foo} :  R & D

If the config file contains

{ 'foo': 'R & D', 'filename': 'index.txt' }

then substitutions are as follows

${foo}  :  R & D
${!foo} :  R & D
${&foo} :  R & D

Config Files

Each config file contains a python dict and is 1:1 with an output file specified by the 'filename' key. Example,

    '_blocks': ['index-header.htm',
                ['index-item.htm', 'pages/*.cfg'],
    'filename': 'index.html',
    'author': 'T.S. Author'

The 'filename' key is special. It can be used a placeholder in template files. This is useful when constructing links. It is also the name of the file used for all output for the config. It will be joined with the directory given by the -o option which uses "out" as the default.

The _blocks key is special. It cannot be used as a placeholder. It contains a list of blockspecs. A blockspec can be a string or a list.

If a blockspec is a string, it's a template file that has placeholders to be filled by keys from the current config and written to 'filename'.

If it is a list, it is helpful to think of it as an "index config". The first element in the list is an "item template" file, and the remaining elements are "item config" files. The item template is filled repeatedly by making a config that is a copy of the index config updated with values from the item config. Each instance of the filled item template is written to the file given by the 'filename' key of the index template.