One-click templating Using Jinja and cookiecutter to instantly create documents in your company's style and configuration. One problem I've had over the last couple of year is how to both source control a document template on Git, yet make it easily available to copy. Users would resort to forking or cloning the template, then manually adjusting the pre-existing template configuration for a new document. This process was cumbersome, unintuitive, and is not the intended usage of forking or cloning. Using cookiecutter allows us to duplicate any repository and pass command-line variables into the generated folder's files using Jinja templating. This means we can essentially copy/paste a source controlled template folder, yet not inherit any Git history or other configuration setups. We now have a scalable, easy, and instant solution for users to create a document locally using a company's styling and configuration. Jinja variables in the Sphinx configuration file: ```python # -- Project variables ------------------------------------------------------- project = '{{ cookiecutter.project_name }}' gitlab_ref = '{{ cookiecutter.gitlab_ref }}' version = '{{ cookiecutter.version }}' default_branch = '{{ cookiecutter.default_branch }}' ``` To setup a document: ```bash cookiecutter git@gitlab.com/path/to/template.git ```
1 minute read | Concept

One-click templating

Using Jinja and cookiecutter to instantly create documents in your company's style and configuration.

One problem I’ve had over the last couple of year is how to both source control a document template on Git, yet make it easily available to copy. Users would resort to forking or cloning the template, then manually adjusting the pre-existing template configuration for a new document. This process was cumbersome, unintuitive, and is not the intended usage of forking or cloning.

Using cookiecutter allows us to duplicate any repository and pass command-line variables into the generated folder’s files using Jinja templating.

This means we can essentially copy/paste a source controlled template folder, yet not inherit any Git history or other configuration setups.

We now have a scalable, easy, and instant solution for users to create a document locally using a company’s styling and configuration.

Example

Jinja variables in the Sphinx configuration file:

# -- Project variables -------------------------------------------------------

project = '{{ cookiecutter.project_name }}'
gitlab_ref = '{{ cookiecutter.gitlab_ref }}'
version = '{{ cookiecutter.version }}'
default_branch = '{{ cookiecutter.default_branch }}'

To setup a document:

cookiecutter git@gitlab.com/path/to/template.git
See also
cookiecutter

Home | Contact