Why is there no place after "Hello" in my Closure template?

I am trying to teach myself how to close patterns. I made a simple simple.soy file:

{namespace examples.simple} /** * says hello to the world * @param? name Optional parameter specifying who you are greeting. */ {template .hiWorld} Hello {if $name} {$name}! {else} world! {/if} {/template} 

After compiling and calling document.write(examples.simple.hiWorld(); however, the displayed line has no space between "Hello" and "world": Helloworld!

Why not?

+4
source share
1 answer

Closure Templates handles row concatenation as follows:

Inside the template, you can backslide the lines as much as you want, because the template compiler removes all line terminators and spaces at the beginning and end of lines, including spaces preceding the comment of the rest of the line. The compiler completely removes empty lines that consist only of spaces. Sequential lines are concatenated according to the following heuristics: if the connection location borders a template or HTML tag on both sides, the lines are concatenated without a space . If the connection location does not limit the template or HTML tag on both sides, the lines are concatenated with one space.

To add a space in Closure Templates, where necessary, use the special character command {sp} . In the event that unwanted space is inserted, you can delete it using the {nil} command. For string connection examples, see features.soy .

simple.soy will become:

 {namespace examples.simple} /** * says hello to the world * @param? name Optional parameter specifying who you are greeting. */ {template .hiWorld} Hello{sp} {if $name} {$name}! {else} world! {/if} {/template} 
+6
source

All Articles