Sri
Sri

Reputation: 49

Mustache.js should be able to handle/display empty string

 {{#Version}} Product Version={{{Version}}}{{Version}}

I am completely new to mustache.js, apologies if the question is not clear.

In the above line i am able to get Product Version if the version is not empty but i also wanted to be able to get Product Version even when Version is empty.

Mustache will drop 'Product Version' from the output if Version is empty.

Product Version =''

Upvotes: 3

Views: 5938

Answers (2)

hunghoang
hunghoang

Reputation: 21

You can show the version if it is not empty and show anything otherwise:

{{#Version}}<b>{{Version}}</b>{{/Version}} {{^Version}}Anything{{/Version}}

Upvotes: 2

moondaisy
moondaisy

Reputation: 4491

This way you can handle empty values so you still get ProductVersion:

Product Version={{#Version}}{{{Version}}}{{/Version}}{{^Version}}''{{/Version}}

Where {{^Version}}{{/Version}} is called an inverted section and will be rendered if the value of that section's tag is null, undefined, false, falsy or an empty list. As it is explained in the doc.

Upvotes: 4

Related Questions