Template variables allow you to create dynamic content in your StructKit configurations. This page covers all aspects of working with variables.
StructKit uses custom Jinja2 delimiters to avoid conflicts with YAML and other content:
- Variables:
{{@and@}} - Blocks:
{%@and@%} - Comments:
{#@and@#}
Examples are shown below and throughout this page.
Use template variables by enclosing them in {{@ and @}}:
files:
- README.md:
content: |
# {{@ project_name @}}
Welcome to {{@ project_name @}}!For control structures, use block notation:
- Start block:
{%@ - End block:
%@}
files:
- config.yaml:
content: |
{%@ if environment == "production" @%}
debug: false
{%@ else @%}
debug: true
{%@ endif @%}Use comment notation to document your templates:
- Start comment:
{#@ - End comment:
@#}
files:
- app.py:
content: |
{#@ This is a template comment @#}
app_name = "{{@ project_name @}}"StructKit provides these built-in variables:
file_name: The name of the file being processedfile_directory: The directory containing the file being processed
Define variables that prompt users for input. When running in interactive mode, StructKit will display the variable's description to help users understand what value is expected:
variables:
- project_name:
description: "The name of your project"
type: string
default: "MyProject"
- author_name:
description: "Your name"
type: string
# No default = interactive prompt
- port:
description: "Application port"
type: integer
default: 8080When prompted interactively, variables with descriptions will display with contextual icons, bold variable names, and clean formatting:
🚀 project_name: The name of your project
Enter value [MyProject]:
🌍 environment: Target deployment environment
Options: (1) dev, (2) staging, (3) prod
Enter value [dev]:
For variables without descriptions, a more compact format is used:
🔧 author_name []:
⚡ enable_logging [true]:
Note: Variable names appear in bold in actual terminal output for better readability.
Contextual Icons: StructKit automatically selects appropriate icons based on variable names and types:
- 🚀 Project/app names
- 🌍 Environment/deployment variables
- 🔌 Ports/network settings
- 🗄️ Database configurations
- ⚡ Boolean/toggle options
- 🔐 Authentication/secrets
- 🏷️ Versions/tags
- 📁 Paths/directories
- 🔧 General variables
Note: The description field is displayed in interactive mode only. You can also use the legacy help field which works the same way.
string: Text valuesinteger: Numeric valuesnumber: Floating-point valuesboolean: True/false values
Interactive enum selection: when a variable defines enum and you are in interactive mode, StructKit will display numbered choices and accept either the number or the exact value. Press Enter to accept the default (if any).
Example prompt:
❓ Enter value for ENV [dev] (1) dev, (2) prod:
# Typing `2` selects `prod`, typing `prod` also works.
You can now enforce types and validations in your variables schema:
required: trueto require a value (non-interactive runs will error if missing)enum: [...]to restrict values to a setregex/patternto validate string formatmin/maxto bound numeric valuesenvordefault_from_envto set defaults from environment variables
Example:
variables:
- IS_ENABLED:
type: boolean
required: true
- RETRY:
type: integer
min: 1
max: 5
- ENV:
type: string
enum: [dev, prod]
- TOKEN:
type: string
env: MY_TOKENStructKit includes custom filters for common tasks:
Generate a random UUID v4 string.
files:
- id.txt:
content: |
id: {{@ uuid() @}}Return the current UTC time in ISO 8601 format.
files:
- stamp.txt:
content: |
generated_at: {{@ now() @}}Read an environment variable with an optional default.
files:
- .env.example:
content: |
TOKEN={{@ env("TOKEN", "changeme") @}}Read the contents of a file on disk. Returns empty string on error.
files:
- README.md:
content: |
{{@ read_file("INTRO.md") @}}Serialize and parse YAML.
files:
- data.yml:
content: |
{{@ some_dict | to_yaml @}}# Assume str_var holds YAML string
{%@ set obj = str_var | from_yaml @%}Serialize and parse JSON.
files:
- data.json:
content: |
{{@ some_dict | to_json @}}# Assume str_var holds JSON string
{%@ set obj = str_var | from_json @%}Fetch the latest release version from GitHub:
files:
- Dockerfile:
content: |
FROM node:{{@ "nodejs/node" | latest_release @}}Requirements: Set GITHUB_TOKEN environment variable for private repos.
Convert strings to URL-friendly slugs:
files:
- "{{@ project_name | slugify @}}.conf":
content: |
server_name {{@ project_name | slugify @}};Options: Optional separator character (default: -)
Get the default branch name of a GitHub repository:
files:
- .github/workflows/ci.yml:
content: |
on:
push:
branches: [ {{@ "httpdss/struct" | default_branch @}} ]Pass additional variables to nested structures:
folders:
- frontend/:
struct: project/react
with:
app_name: "{{@ project_name @}}-frontend"
port: 3000
- backend/:
struct: project/node
with:
app_name: "{{@ project_name @}}-backend"
port: 8000Variables defined in with are merged with global variables and take precedence.
files:
- docker-compose.yml:
skip: "{{@ not use_docker @}}"
content: |
version: '3.8'
services:
app:
image: {{@ project_name | slugify @}}:latestfiles:
- "src/{{@ module_name @}}/index.js":
content: |
// {{@ module_name @}} module
export default {};files:
- config/{{@ environment @}}.yml:
content: |
{%@ if environment == "production" @%}
database_url: {{@ production_db_url @}}
{%@ else @%}
database_url: sqlite:///dev.db
{%@ endif @%}