Variable-based output filenamesΒΆ

This document explains how to render dynamic filenames.

When rendering a directory, it is sometimes useful to use variables in the filenames to output.

Tip

This is useless for single files, since most clients allow you to choose the name of the output file.

Note

In the examples below, let’s communicate with a diecutter server using Python requests.

This diecutter serves diecutter’s demo templates.

The diecutter_url variable holds root URL of diecutter service, i.e. something like http://diecutter.io/api/.

When rendering directories, templates having +variable+ in the filename will be resolved against the context data:

>>> url = diecutter_url + 'simple-tree/'
>>> response = requests.get(url)
>>> print response.content
+name+.txt
>>> response = requests.post(url, {'name': 'demo'})
>>> archive = tarfile.open(fileobj=StringIO(response.content))
>>> print archive.getnames()
['demo.txt']

Tip

The “variable-based filenames” feature is meant for simple cases. If you need advanced things for filenames, use the dynamic trees feature.

Notice that “variable-based filenames” behaviour is disabled when using the dynamic trees.