Skip to content

Dependencies

Dependencies let you compose templates by running child templates as part of a parent template. This is useful for building complex project structures from smaller, reusable template modules.

dependencies:
- name: backend
template-url: ../go-service
output-folder: ./backend
FieldRequiredDescription
nameYesA unique name for this dependency
template-urlYesPath to the child template (local or remote go-getter URL)
output-folderYesWhere to write the child template’s output, relative to the current output
skipNoA Go template expression — if it evaluates to true, the dependency is skipped
dont-inherit-variablesNoIf true, the child template won’t inherit parent variables
variablesNoOverride or add variables for this dependency
var_filesNoYAML files to load variables from for this dependency
for_eachNoA list of values — the dependency is rendered once per item
for_each_referenceNoName of a list variable — the dependency is rendered once per item in that list

Suppose you have a fullstack-app template that composes a Go backend and a React frontend from separate, reusable templates:

templates/
├── fullstack-app/
│ └── boilerplate.yml # Parent template
├── go-service/
│ ├── boilerplate.yml
│ ├── main.go
│ └── Dockerfile
└── react-app/
├── boilerplate.yml
├── package.json
└── src/
└── App.tsx

fullstack-app/boilerplate.yml — the parent template that ties everything together:

variables:
- name: ProjectName
description: Name of the project
type: string
- name: IncludeDocker
description: Include Docker configuration?
type: bool
default: true
dependencies:
- name: backend
template-url: ../go-service
output-folder: ./backend
variables:
- name: ServiceName
default: "{{ .ProjectName }}-api"
- name: Port
default: "8080"
- name: frontend
template-url: ../react-app
output-folder: ./frontend
variables:
- name: AppName
default: "{{ .ProjectName }}-web"
- name: ApiUrl
default: "http://localhost:8080"
- name: docker
template-url: ../docker-compose
output-folder: .
skip: "{{ not .IncludeDocker }}"

Running this generates a complete project in one command:

Terminal window
boilerplate \
--template-url ./templates/fullstack-app \
--output-folder ./my-project \
--var ProjectName="Acme" \
--var IncludeDocker=true

The output:

my-project/
├── backend/
│ ├── main.go # Rendered from go-service template
│ └── Dockerfile
├── frontend/
│ ├── package.json # Rendered from react-app template
│ └── src/
│ └── App.tsx
└── docker-compose.yml # Rendered from docker-compose template

Each child template is self-contained — go-service and react-app can also be used independently. The parent simply orchestrates them and passes the right variables down.

By default, child templates inherit all variables from the parent. You can override specific values:

dependencies:
- name: backend
template-url: ../go-service
output-folder: ./backend
variables:
- name: ServiceName
default: "{{ .ProjectName }}-api"
- name: Port
default: "8080"

Set dont-inherit-variables: true to prevent any parent variables from being passed down.

Use the skip field with a Go template expression to conditionally skip a dependency:

dependencies:
- name: docker
template-url: ../docker-template
output-folder: .
skip: "{{ not .IncludeDocker }}"

Render a dependency once for each item in a static list:

dependencies:
- name: microservice
template-url: ../service-template
output-folder: "./services/{{ .__each__ }}"
for_each:
- users
- orders
- notifications

Inside the child template, access the current item with {{ "{{" }} .__each__ {{ "}}" }}.

Reference a list variable instead of a static list:

variables:
- name: ServiceList
type: list
default:
- users
- orders
dependencies:
- name: microservice
template-url: ../service-template
output-folder: "./services/{{ .__each__ }}"
for_each_reference: ServiceList

Load variables from YAML files specific to a dependency:

dependencies:
- name: production
template-url: ../deploy-template
output-folder: ./deploy
var_files:
- ../vars/production.yml

Dependencies can have their own dependencies, creating a tree of templates. Variable inheritance flows down through the entire chain.

  1. Parent variables are gathered
  2. Parent before hooks run
  3. Each dependency is processed (recursively):
    • Child variables are merged with inherited values
    • Child before hooks run
    • Child dependencies are processed
    • Child template files are rendered
    • Child after hooks run
  4. Parent template files are rendered
  5. Parent after hooks run