Write Custom Templates#
If the default configuration type does not meet your needs and extra_lines is not sufficient, you can create a custom template set.
Note
Custom templates require modifying the plone.meta source. This is an advanced topic. For most use cases, customizing via .meta.toml is the recommended approach.
How the template system works#
plone.meta uses a Jinja2 FileSystemLoader with two search paths, in order:
src/plone/meta/<config_type>/– the active configuration typesrc/plone/meta/default/– the fallback
When a template is requested (e.g. tox.ini.j2), Jinja2 looks in the config type directory first.
If it finds the file there, it uses that version.
Otherwise, it falls back to default/.
This means you can override individual templates while inheriting the rest from default/.
Create a custom configuration type#
In your fork or local clone of plone.meta, create a new directory alongside
default/:mkdir -p src/plone/meta/mytype
Copy only the templates you want to change:
cp src/plone/meta/default/tox.ini.j2 src/plone/meta/mytype/
Edit the copied template. Templates use a custom Jinja2 syntax with
%(variable)sfor variable substitution instead of the standard{{ variable }}:%(extra_lines)s %(test_runner)s %(constraints_file)s
See Generated Files for the full list of templates and their variables.
Register the new type by adding it to the
choiceslist inconfig_package.py:parser.add_argument( "-t", "--type", choices=[ "default", "mytype", ], ... )
Create a
packages.txtfile in your new directory (can be empty):touch src/plone/meta/mytype/packages.txtReinstall plone.meta:
venv/bin/pip install -e .
Use the custom type#
Apply the custom configuration to a repository:
venv/bin/config-package --type mytype /path/to/package
The type is stored in .meta.toml under [meta] template, so subsequent runs do not need the --type flag.
Template variables#
All templates receive their variables from .meta.toml via the _get_options_for() method.
The variable names correspond to the keys in each .meta.toml section.
Additionally, some variables are computed:
config_typeThe active configuration type name (e.g.
"default","mytype").news_folder_existsTrueif anews/directory exists in the target repository.changes_extension"md"or"rst"depending on whetherCHANGES.mdexists.prime_robotframeworkTrueifplone.app.robotframeworkis detected as a dependency.package_nameThe repository directory name (or overridden via
.meta.toml).
Considerations#
Keep your custom templates in a fork or branch. Upstream plone.meta only ships the
defaulttype.When upstream templates change, you will need to merge those changes into your overridden files.
If your customization is generally useful, consider requesting it upstream as a new
extra_linesoption instead.