Skip to content

Concatenation of 2 strings in variables #1168

Discussion options

You must be logged in to vote

Hi @github-reader, I've moved this issue to a discussion instead as this is more of a question than a bug report.

There are a number of ways to concatenate strings in the Go templating language that gomplate uses. Usually, what I do is use the print keyword:

$ gomplate -i '{{ $var1 := "val1" }}{{ $var2 := "val2" }}{{ $var3 := print $var1 $var2 }}{{ $var3 }}'
val1val2

You can also use printf if you're familiar with that style of syntax:

$ gomplate -i '{{ $var1 := "val1" }}{{ $var2 := "val2" }}{{ $var3 := printf "%s%s" $var1 $var2 }}{{ $var3 }}'
val1val2

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hairyhenderson
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
Converted from issue

This discussion was converted from issue #1166 on June 01, 2021 13:10.