What does that expression mean?

Asked

Viewed 104 times

3

Studying a little the Node-Red I came across the following expression, {{#header.url}.

Several expressions of the type are present in the code, for example: {{/header.url}}, {{#header.image}}, etc. Follows a code snippet:

<span class="logo">{{#header.url}}<a href="{{.}}">{{/header.url}}{{#header.image}}<img src="{{.}}" title="{{version}}">{{/header.image}} <span>{{ header.title }}</span>{{#header.url}}</a>{{/header.url}}</span>
<ul class="header-toolbar hide">

Would anyone know what that expression is doing?

1 answer

3


This is very typical of Mustache, a template language that compiles HTML pata.

The Javascript version (Mustache.js) has an example in the documentation:

View:

{
  "person": false
}

Template:

Shown.
{{#person}}
Never shown!
{{/person}}

Output:

Shown.

That is, an object with properties is configured, then in the template what is between {{#person}} and {{/person}} will be included if pessoa for true.

  • So for example, instead of me writing all the html to upload images, links and so on, I can set up the mustache so that it generates all this for me?

  • @Fernandomessiasdasilva in particular mustache is very fanatical about logic. They "ban" logic in the template. If you can have the logic in JS and make the template show what you want great. Otherwise there are many other languages that do this. I think my answer goes against your question. If you have another specific question about a situation where you want to write html logically for images and links: I suggest you ask another question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.