linkedin / linkedin/dustjs

conditional based on parameter undefined/defined fail when value is parameter

Open
#782 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.9k
Forks
461
PR merge metrics
No merged PRs in 30d

Description

If I reference a value that is undefined in the current context, I get an unwelcome warning:
e.g., with parent context
```
{
data: [{
item : "exampleA",
blah : "This example"
},{
item : "exampleB"
}]
}
```
And a template "boo.dust"
```
{blah} is good
```

Invoked as a section:
```
{#data}
{> boo/}
{/data}
```
The second entry, exampleB, gives a warning:

> [DUST:INFO] Cannot find reference '{blah}' in template 'boo'

What I need to do is conditionally render a partial like this:
```
{@exists key='blah'}
{blah} is good
{/exists}
```

I wrote a helper that works fine in the above example, but it fails if instead of passing the key in the context, I send it as a parameter, e.g.,
**FAIL**
```
{
data: [{
item : "exampleA",
},{
item : "exampleB"
}]
}
```
And a template "boo.dust"
```
{blah} is good
```

Invoked as a section:
```
{#data}
{> boo blah="THIS EXAMPLE"/}
{/data}
```

I tried using {?exists/} as described in http://www.dustjs.com/docs/syntax/ but there isn't any actual example code, so it's not clear how to do it and I couldn't get it working.

Any pointers welcome.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the `boo.dust` examples and the documented `{?exists/}` syntax, then reproduce the difference between a context key and the partial parameter `blah="THIS EXAMPLE"`. Trace how Dust resolves the parameter inside the `data` section and verify whether the conditional can render without an undefined-reference warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.