Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jandrieu opened this issue Jul 27, 2018 · 1 comment

Comments

@jandrieu
Copy link

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.

@damondine
Copy link

damondine commented Sep 5, 2018

Just opened an issue, so thought I would help with a question as well.

Using your example above, your partial should look like this:

{?blah}  
    {blah} is good  
{/blah}

The full output of the template would look like the following:

{#data}
  {?blah}
    {blah} is good
  {/blah}
{/data}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants