Skip to content

passing list to template #479

@bsdlp

Description

@bsdlp

I would like to be able to pass a list to the templates. See the two code blocks at the end of this post for an example. Right now it appears that if you pass a list in the config object, it's read as a list of options for that key.

I know that you can use str.split() in the jinja2 template, but that's not a real solution, since it's impossible to "escape" the character that's used as the delimiter. What's the best solution here? I would prefer to be able to pass a list in the json object and call it a day, but obviously that doesn't work for the user input prompts.

  • cookiecutter.json:
{
  "build_steps": [
     "do_something",
     "do_something_else"
  ]
}
  • Dockerfile:
FROM something

{% for step in cookiecutter.build_steps %}
RUN {{ step }}
{% endfor %}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions