Skip to content

Multiple rendering - Render template once per CSV record #2124

Closed Answered by safferyj
safferyj asked this question in Q&A
Discussion options

You must be logged in to vote

On Windows, with

type template.tmpl
{
    "a": "{{.a}}",
    "b": "{{.b}}",
    "c": "{{.c}}"
}

and

type data.csv
a,b,c
1,2,hello
3,4,world
5,6,yippee
7,8,yay

then

gomplate --plugin curl=curl.exe -t template.tmpl -d data.csv -i "{{$data := include `data` | csvByRow}}{{range $data}}{{$render := tmpl.Exec `template.tmpl` .}}{{curl `--silent` `--json` $render `http://api`}}{{end}}"

will make the following four distinct POST API calls

{
    "a": "1",
    "b": "2",
    "c": "hello"
}
{
    "a": "3",
    "b": "4",
    "c": "world"
}
{
    "a": "5",
    "b": "6",
    "c": "yippee"
}
{
    "a": "7",
    "b": "8",
    "c": "yay"
}

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@safferyj
Comment options

@hairyhenderson
Comment options

@safferyj
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by safferyj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants