What does `{{{variable}}}` mean in handlebars? - handlebars.js

What does triple curly braces mean in handlebars template syntax?
For example
{{{variable}}}
I cannot find any documentation.
Thanks

Because it was originally designed to generate HTML, Handlebars escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.
Source: https://handlebarsjs.com/guide/#html-escaping
Found via: https://github.com/wycats/handlebars-site/issues/28

Related

How to access map in template string?

I want to use values from gradle.properties that should go into a template string.
A naive first:
println("${project.properties[somekey]}")
doesn't work: Unresolved reference: somekey
So, quotes required?
println("${project.properties[\"somekey\"]}")
is completely broken syntax: Expecting an expression for the first .
I couldn't find any example how to do this, yet the official documentation says expressions.
Question: is it possible to access a map in string template, and if so, how?
Yes and as follows:
"${project.properties["someKey"]}"
assuming the Map has the following signature: Map<String, Any?> (or Map<Any...)
Alternatives:
"${project.properties.getValue("someKey")}"
"${project.properties.getOrElse("someKey") { "lazy-evaluation-default-value" }}"
"${project.properties.getOrDefault("someKey", "someFixedDefaultValue")}"
Basically all the code you put in the ${} is just plain Kotlin code... no further quoting/escaping required, except for the dollar sign $ itself, e.g. use "\$test" if you do not want it to be substituted with a variable named test or """${"$"}test""" if you use a raw string
Note that in this println case the following would have sufficed as well (which also goes for all the shown alternatives above. You may omit the outer surrounding quotes and ${} altogether):
println(project.properties["someKey"])
See also Basic types - String templates

Literal braces in Handlebars template

I'm having difficulties including braces { } in a Handlebars template so that it didn't interfere with Handlebars syntax.
Specifically, I want to have a template like this:
{{{sometag}}}
Except that I want the first and the last braces to be rendered literally, rather than be a part of Handlebar's "non-escaped expression" syntax.
For now, the shortest portable syntax I could come up with is {{#with "{"}}{{.}}{{/with}}, so that the template that I want would look like:
{{#with "{"}}{{.}}{{/with}}{{sometag}}{{#with "}"}}{{.}}{{/with}}
I could use HTML entities (like https://stackoverflow.com/a/16278085/3088208 suggests), or insert an HTML comment after the initial { and before the final }, but these solutions, while practical, depend on HTML which makes them limited.
P. S. Found a duplicate question: Escaping curly brackets standing next to expression in handlebars
For anyone who lands here in the future, this solution worked for me Render double curly-brackets inside handlebars partial
TL;DR Add a \ to your value eg \{{{whatever}}} will render {{{whatever}}}
I was also searching for this solution and couldn't find anything. So I've created helper
Handlebars.registerHelper('bracket', function(num, options = num) {
const i = Number.isInteger(num) ? num : 1;
const open = '{'.repeat(i);
const close = '}'.repeat(i);
return `${open}${options.fn(this)}${close}`;
});
You can use it like
{{#bracket 2}}styles.{{name}}{{/bracket}}
it will give
{{styles.Name}}
If number of brackets was not specified it will be one.

Do I need an empty sequence () in addition to a comment in an enclosed expression?

When trying to use the oXygen editor to comment out a node inside of an element oXygen simply wrapped it into (:<foo>foo 1</foo>:), but I then found out that that way the node did not get commented out but was rather prefixed by a text node with (: and suffixed by a text node with :).
Then I looked up the syntax and found out you need to use an enclosed expression {(:<foo>foo 1</foo>:)} instead to have access to the comment syntax.
However, while BaseX and Saxon 9.8 happily accept {(:<foo>foo 1</foo>:)}, Altova complains and needs an additional empty sequence {(:<foo>foo 1</foo>:)()}.
https://www.w3.org/TR/xquery-31/#doc-xquery31-EnclosedExpr suggests in XQuery 3.1 the expression inside curly braces is optional and defaults to ().
Does this also mean that in XQuery 3.1 it should suffice to use simply the comment inside of the curly braces, without an empty sequence?
So to summarize, Saxon and BaseX allow me to use <root>{(:<foo>foo 1</foo>:)}</root> while Altova complains about incorrect syntax, forcing me to use <root>{(:<foo>foo 1</foo>:)()}</root>.
Is that still necessary in XQuery 3.1?
Sounds like a bug in their commenter, which is pretty common in XQuery editors. Within in an element - and assuming you are using direct element constructors, not computed element constructors - use XML comments:
<hello>world
<!-- Don't print me -->
</hello>
Computed element constructors still use XQuery comments:
element hello {
'world' (: Don't print me :)
}

What is the difference between double curly braces and triple curly braces for Handlebars.js

For instance, you can see {{{body}}} and in the templates, you are able to do something like {{data.page.hero.text}}
Is there any significant difference we should be aware of?
Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.
Reference: https://handlebarsjs.com/guide/expressions.html#html-escaping
Depending on your use case and logic, you may add an option "noEscape" set to true when compiling the template if you want to use {{ }} when {{{ }}} are required to successfully replace the templates.
For example: replacing with JSON values.
From the documentation:
var template = Handlebars.compile('{{foo}}', { noEscape: true });
noEscape: Set to true to not HTML escape any content.

JMSSecurityExtraBundle nested AND/OR expressions

I have this #PreAuthorize annotation:
#PreAuthorize("(hasRole('PERM_EDIT_ALL_CAMPAIGNS') or (has_role('PERM_EDIT_OWN_CAMPAIGNS') and isCampaignAccountManager(#id))) and (hasRole('PERM_EDIT_ALL_PUBLISHERS') or (has_role('PERM_EDIT_OWN_PUBLISHERS') and isAffiliateAccountManager(#paramFetcher.get('affiliate_id'))))")
I get the following error:
Expected primary expression, but got \u0022has_role\u0022 of type T_NONE at position
40 (0-based)
So the error looks like to appear after the bracket beginning here:
(has_role('PERM_EDIT_OWN_CAMPAIGNS') and isCampaignAccountManager(#id)))
Is there any way to add brackets in and/or expressions?
Thanks in advance
OMG!! sorry, I just realized after I wrote the question. I was using 'has_role' instead 'hasRole' :(

Resources