While testing the multiple file templating example I faced below errors.
# p2 --enable-write_file -t template.p2 -i input.yml
Error: Invalid trailing arguments: [--enable-write_file -t template.p2 -i input.yml]
Usage: p2 [global options]
Global options:
-h, --help Show this help
-v, --version Print version
-d, --debug Print Go serialization to stderr
-f, --format Input data format [valid values: env,yaml,json]
--use-env-key Treat --input as an environment key name to read.
-t, --template Template file to process
-i, --input Input data path. Leave blank for stdin.
-o, --output Output file. Leave blank for stdout.
--enable-filters Enable custom p2 filters.
--enable-noop-filters Enable all custom filters in noop mode. Supercedes --enable-filters
I had to run below to avoid the error.
#p2 -t template.p2 -i input.yml --enable-filters write_file
Also the input.yml and template.p2 seemed to have wrong content. Had to re-write to below to get the desired output.
users:
- user:
name: Mike
content: This is Mike's content.
- user:
name: Sally
content: This is Sally's content.
- user:
name: Greg
content: This is Greg's content.
template.p2
{% macro user_content(content) %}
{{content|safe}}
{% endmacro %}
{% for user in users %}
## {{user.name}}.txt output
{% set filename = user.name|stringformat:"%s.txt" %}
{{ user_content( user.content ) | write_file:filename }}
##
{% endfor %}
If this is ok shall I raise a PR to fix this in the readme?
While testing the multiple file templating example I faced below errors.
I had to run below to avoid the error.
#p2 -t template.p2 -i input.yml --enable-filters write_file
Also the
input.yml
andtemplate.p2
seemed to have wrong content. Had to re-write to below to get the desired output.template.p2
If this is ok shall I raise a PR to fix this in the readme?