Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a Golang template when "{" or "}" are in the static part of the template?

My Problem is that, I want to build a letter generator, which first builds a latex-file from user input, and then compiles this via latex to PDF.

The template contains multiple lines like this:

\setkomavar{signature}{{{.Name}}}

The latex part is \setkomavar{signature}{}, and the template part from go is {{.Name}}.

When I try to load the template, it throws this error:

panic: template: letter.tmpl:72: unexpected "}" in command

Is there a trick to help the parser handling such a situation?

Thanks in advance,

Tino

like image 446
user2326871 Avatar asked May 23 '13 07:05

user2326871


1 Answers

A better solution is actually to just use the built in whitespace operators, like:

\setkomavar{signature}{ {{- .Name -}} }

The - at the beginning and end will remove whitespace between that token and the next non-template token.

Hope that helps, see the docs for more detail

like image 137
Steve Coffey Avatar answered Oct 03 '22 21:10

Steve Coffey