Skip to content

Commit afb4d12

Browse files
docs: Add Advanced use cases > Dynamic file naming to README (LIB-3473) (#244)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Josh Padnick <[email protected]>
1 parent ba60dda commit afb4d12

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ Learn more about boilerplate in the following sections:
162162
1. [Template helpers](#template-helpers)
163163
1. [Deprecated helpers](#deprecated-helpers)
164164
1. [Partials](#partials)
165+
1. [Advanced use cases](#advanced-use-cases)
165166

166167
#### Boilerplate command line options
167168

@@ -1120,6 +1121,33 @@ partials:
11201121
- "{{ .TemplatesRoot }}/css/*.css"
11211122
```
11221123

1124+
## Advanced use cases
1125+
1126+
### Dynamic file naming
1127+
1128+
Boilerplate supports using variables and template helpers directly in filenames. This allows you to dynamically generate file names based on the variables you define in your `boilerplate.yml` file.
1129+
1130+
For example, with the following variable definition:
1131+
1132+
```yaml
1133+
variables:
1134+
- name: Singular
1135+
description: The singular form the noun, e.g. BigWidget
1136+
```
1137+
1138+
You can create a template file named `{{ .Singular | snakeCase }}_entity.go` which will generate a file like `big_widget_entity.go` when the Singular variable is set to "BigWidget".
1139+
1140+
Another example:
1141+
1142+
```yaml
1143+
variables:
1144+
- name: RootTerragruntFileName
1145+
type: string
1146+
default: "root.hcl"
1147+
```
1148+
1149+
With this variable, you can have a template file named `{{ .RootTerragruntFileName }}` which will generate a file named according to the value of RootTerragruntFileName.
1150+
11231151
## Alternative project generators
11241152

11251153
Before creating Boilerplate, we tried a number of other project generators, but none of them met all of our

0 commit comments

Comments
 (0)