Answer the question
In order to leave comments, you need to log in
How in go, in the template package, not all tags should be translated into text?
How in go, in the template package, to translate not all tags into text? For example, do not translate the h1, i, div tags with the do class, etc., is this possible?
Answer the question
In order to leave comments, you need to log in
The job of a template engine is to assemble a string from the template(s) that are essentially strings + inject custom data into them. The template engine doesn't care if you have tags in these lines, or not tags, all it is interested in is the syntactic constructions of the template engine itself, for data substitution.
Leading to the next - if you do not need to show part of the template - write a condition.
First, we take html/template and read the sources, we see that text/template is used there, then we read the godoc for both packages and we see that text/template is basic and has more useful information. There we find the block.
Examples
Here are some example one-line templates demonstrating pipelines and variables. All produce the quoted word "output":{{"\"output\""}} A string constant. {{`"output"`}} A raw string constant. {{printf "%q" "output"}} A function call. {{"output" | printf "%q"}} A function call whose final argument comes from the previous command. {{printf "%q" (print "out" "put")}} A parenthesized argument. {{"put" | printf "%s%s" "out" | printf "%q"}} A more elaborate call. {{"output" | printf "%s" | printf "%q"}} A longer chain. {{with "output"}}{{printf "%q" .}}{{end}} A with action using dot. {{with $x := "output" | printf "%q"}}{{$x}}{{end}} A with action that creates and uses a variable. {{with $x := "output"}}{{printf "%q" $x}}{{end}} A with action that uses the variable in another action. {{with $x := "output"}}{{$x | printf "%q"}}{{end}} The same, but pipelined.
In other words, do {{`{`}} and {{`}`}} or {{"{"}} and {{"{"}} where you want to "abfuscate the tag".
In order not to constantly write a bunch of brackets, you can write Delims("{", "}"), but find out exactly how :)
Perhaps there are several more solutions if the tags that need to be ignored are not in the text inserted into the template.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question