Using the split function to process comma-separated strings
Published on August 28th, 2025Template
Actions used
You can check the available actions if you visit /create/actions.
Walkthrough
Example Template
yaml
---
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: split-string-example
title: Split comma-separated string and process each value
description: This scaffolder takes a comma-separated string input and processes each value individually.
spec:
owner: roadie
type: service
parameters:
properties:
things:
title: Comma-separated list of things
type: string
description: Enter items separated by commas (e.g., "item1,item2,item3")
steps:
- id: log-each-string
name: Log each string
action: debug:log
each: ${{ parameters.things | split(",") }}
input:
message: ${{ each.value }}
Breakdown
Parameters
This section configures the frontend for your template. The user provides a single string input that contains multiple values separated by commas.
yaml
things:
title: Comma-separated list of things
type: string
description: Enter items separated by commas (e.g., "item1,item2,item3")
Steps
debug:log with split function
This step demonstrates how to use the Nunjucks split filter to convert a comma-separated string into an array, then iterate over each value using the each keyword.
yaml
- id: log-each-string
name: Log each string
action: debug:log
each: ${{ parameters.things | split(",") }}
input:
message: ${{ each.value }}
The split(",") filter takes the input string and splits it at each comma, creating an array of individual strings. The each keyword then iterates over this array, making each value available as each.value.
How it works
- User enters:
"apple,banana,cherry" - The
split(",")filter converts it to:["apple", "banana", "cherry"] - The
eachiteration processes each item:- First iteration:
each.value = "apple" - Second iteration:
each.value = "banana" - Third iteration:
each.value = "cherry"
- First iteration:
Use Cases
This pattern is useful for:
- Processing lists of repository names, service names, or component names
- Creating multiple resources based on a simple string input
- Converting user-friendly comma-separated input into actionable data
Further reading
- You can also use for loops to repeat scaffolder steps with array parameters
- Learn about variables in scaffolder for more complex data manipulation