I’m using AngularJS as the front-end JS library, with Go templates within Revel framework to to generate the markup on the back-end.
But both Go and Angular use {{
and }}
for delimiters in their templates. How can I escape them in Go to pass them to AngularJS?
Go's template is designed to be extended by developers, and provides access to data objects and additional functions that are passed into the template engine programmatically. This tutorial only uses functions universally provided in the text/template package, and does not discuss the specifics of data access.
Go template uses names for its objects that are not immediately familiar. Once you have familiarized yourself with the concepts, the canonical documentation becomes easier to read. Not surprisingly, the template is the entire text that is submitted to the template engine to be rendered. The template consists of text and "actions".
Go template outputs everything between actions, including whitespace and line feeds. This can make it challenging to read nested template code. If an action's left delimiter is followed immediately by a minus sign and ASCII space character { {- , all trailing white space is trimmed from the immediately preceding text.
To insert escape characters, use interpreted string literals delimited by double quotes. const s = " First line " + "Second line" fmt.Println(s) First line Second line The escape character denotes a horizontal tab and is a line feed or newline. Double quote escape Use \"to insert a double quote in an interpreted string literal:
0. Go template provides a very limited number of functions universally, and instead relies on the specific implementation to add functions to enhance the user experience. However, print is one of the available functions. Later in the tutorial, there is a list of the built-in functions provided by all Go template environments.
{{"{{"}} {{"}}"}}
produces
{{ }}
A simple workaround would be using
{{`{{Your.Angular.Data}}`}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With