DustJS logic to verify empty string

1.5k Views Asked by At

I need to write logic to check whether the value is empty or it has string. Any help on this.. i tried this following. but it doesn't work in nodejs and throwing error

{@if cond="'{notes}' != '' || '{errors}' != '' "}
   display html
{/if}
2

There are 2 best solutions below

1
smfoote On

The @if helper is deprecated and should not be used. However, based on the code you've given, you should probably be able to use an exists check.

{?notes}
  {?errors}
    {! Display HTML !}
  {/errors}
{/notes}

If that doesn't work for some reason, you could use the @ne helper.

{@ne key=notes value=""}
   ...
{/ne}

If that still isn't good enough, you could try writing a context helper. The documentation on dustjs.com is excellent.

0
myusuf On
{?notes}
  Display HTML
{:else}
  {?errors}
    Display HTML
  {/errors}
{/notes}

should do the trick.