7.1 STL and Open Document Format

You can use the STL and the ODF handler to produce documents. It’s useful to do mailings. The stl_to_odt function allow to use substitution placeholders (ex: ${firstname}) in an ODF file to compute substitutions.

Here a python example to generate a letter:

  !/usr/bin/env python
  # -*- coding: UTF-8 -*-

  from itools.odf.odf import ODTFile, stl_to_odt
  from itools.stl import stl

  namespace = {'firstname': 'Jean',
               'lastname': 'Dupond'}
  # Load the model
  handler = ODTFile('model_letter.odt')
  # Fill the odt file handler with the namespace dictionnary content.
  document = stl_to_odt(handler, namespace)
  # Save the letter
  handler = ODTFile(string=document)
  handler.save_state_to('letter_jean_dupond.odt')