Closed claviska closed 5 years ago
I'm not sure if this is really a bug. I've tested it with the {@getTags} and the {@getAuthors} Helper and both worked as expected. I've put this in my blog.dust:
{@getTags slug="not-existing-tag"}
{#tags}
{name}
{:else}
No tags
{/tags}
{/getTags}
and got the output: No Tags
in the rendered page.
Maybe this issue is a result of ending up in the catch-block as described here?
I'll have to investigate this further then. I was pretty sure you have to explicitly call the else block. In this case, models.user.findAll
won't throw an error if no results are found โย it will just result in an empty array.
Sorry, it's been awhile since I've worked with Dust.js. Unfortunately, it may have been a bad choice longterm since the lib seems to be deprecated by LinkedIn. In hindsight, Nunjucks may have been a better choice. ๐
I created some dust-Files (blog.dust + post.dust) and implemented all of the above named helpers. They all worked like expected - when used in the right context ;)
So, the {:else}-Block is not working in the following cases:
I think this is acceptable an this issue can be closed.
Youโre right. I just found this in the Dust wiki:
https://github.com/linkedin/dustjs/wiki/Dust-Tutorial#Logic_in_Templates
Thanks for investigating this!
As discovered in #104, some helpers do not support the
{:else}
block as documented. This is a relatively easy fix for anyone looking to contribute. ๐The
{:else}
block is an optional block in some helpers that will render when a helper fails to find any suitable results. For example:In code, the correct way to implement
{:else}
looks something like this:Theme Helpers
The following helpers are documented to support the
{:else}
block but currently do not.