A GitHub action to render nunjucks templates.
name: Example
on:
workflow_dispatch:
jobs:
example:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository ⏬
uses: actions/checkout@v4
- name: Render template string 🎬
id: render-template-string
uses: Lehoczky/[email protected]
with:
template: "Hello {{ username | capitalize }}"
vars: |
{
"username": "john"
}
- name: Print output 📽
run: echo "${{ steps.render-template-string.outputs.result }}"
name: Example
on:
workflow_dispatch:
jobs:
example:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository ⏬
uses: actions/checkout@v4
- name: Render template string 🎬
id: render-template-string
uses: Lehoczky/[email protected]
with:
template-path: .github/templates/example.njk
vars: |
{
"username": "john"
}
- name: Print output 📽
run: echo "${{ steps.render-template-string.outputs.result }}"
The GitHub action context and env variables are automatically injected into the templates for convenience:
- name: Render template string 🎬
id: render-template-string
uses: Lehoczky/[email protected]
with:
template: |
GitHub context:
{{ context | dump(2) }}
Env:
{{ env | dump(2) }}
name | description | default |
---|---|---|
template | Nunjucks template string | "" |
template-path | Path to nunjucks template file | "" |
vars | Variables to use in template in JSON format | {} |
auto-escape | Controls if output with dangerous characters are escaped automatically | true |
trim-blocks | Automatically remove trailing newlines from a block/tag | false |
lstrip-blocks | Automatically remove leading whitespace from a block/tag | false |
Either template
or template-path
is required. If both of them are defined, template-path
takes precedence.
To learn more about auto-escape
, trim-blocks
and lstrip-block
, see the official Nunjucks documentation:
https://mozilla.github.io/nunjucks/api.html#configure
name | description |
---|---|
result | Rendered file content |
See development.md