admin管理员组

文章数量:1336699

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

I am pletely 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 =''
 {{#Version}} Product Version={{{Version}}}{{Version}}

I am pletely 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 =''
Share Improve this question asked Mar 14, 2017 at 23:31 Sri Sri 491 silver badge7 bronze badges 1
  • Can you provide an accurate representation of the object you are rendering? I suspect whatever "Product Version" is has a length of zero when it is empty. – IronAces Commented Mar 16, 2017 at 8:00
Add a ment  | 

2 Answers 2

Reset to default 4

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.

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

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

本文标签: javascriptMustachejs should be able to handledisplay empty stringStack Overflow