I have to disable a link in mustache file by getting value from YML configuration (in Dropwizard). If the value is disable, it should hide the element in the page so that user should not able to click the link. Is it possible to do this function?
Asked
Active
Viewed 267 times
1 Answers
3
Mustache is logic-less, so you must provide a boolean value in your YAML file:
href: false
YAML also allows off
and no
as boolean values that map to false
. You can then write a mustache file like this:
<a{{#href}} href="example.com"{{/href}}>
The Text inside {{#href}}
… {{/href}}
will only render if href
exists and is not false
. Note that you must set it to true
for the tag to render.

flyx
- 35,506
- 7
- 89
- 126
-
I tried to implement this for a similar use case. In my attempt i am facing two issues, url is displayed as plain text and second in instances where href=null the hyperlink text is still displayed https://stackoverflow.com/questions/74745046/issue-with-rendering-a-hyperlink-using-mustache?noredirect=1#comment131918311_74745046 – Bisoux Dec 09 '22 at 20:01