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

@key value incorrect when using {{isnt}} helper in an {{each}} loop #262

Open
blueowl0708 opened this issue Apr 24, 2017 · 2 comments
Open

Comments

@blueowl0708
Copy link

version

Gulp with Assemble 0.21.0 + Handlebars-Helpers 0.7.7 (tested in latest versions of both)

description

FYI I've moved this over from the assemble repo at the request of @jonschlinkert.


I'm migrating a site from grunt + assemble to gulp + assemble and I'm having trouble with the following code which works fine on the old build.

In our hbs file there's a YAML object:

    Subject heading:
        open: open

        Article title 1:
            description: Description 1
            url: /url1

        Article title 2:
            description: Description 2
            url: /url2

        Article title 3:
            description: Description 3
            url: /url3

We pass this into a partial for processing

{{#with sub-categories}}
    {{> inc-subcategory-expanders}}
{{/with}}

The partial looks like this:

<div>
    {{#each this}}
        <div {{#if this.open}}class="is-open"{{/if}}>
            <h3 id="{{ dashcase @key }}">{{@key}}</h3>
            <ul id="content-{{ dashcase @key }}">
                {{#each this}}
                    {{#isnt @key "open"}}
                    <li>
                        <a href="{{this.url}}">
                            <h4>{{@key}}</h4>
                            <p>{{this.description}}</p>
                        </a>
                    </li>
                    {{/isnt}}
                {{/each}}
            </ul>
        </div>
    {{/each}}
</div>

And this is the output - the article title is always 'Article title 3'

<div>
    <div class="is-open">
        <h3 id="subject-heading">Subject heading</h3>
        <ul id="content-subject-heading">
            <li>
                <a href="/url1">
                    <h4>Article title 3</h4>
                    <p>Description 1</p>
                </a>
            </li>
            <li>
                <a href="/url2">
                    <h4>Article title 3</h4>
                    <p>Description 2</p>
                </a>
            </li>
            <li>
                <a href="/url3">
                    <h4>Article title 3</h4>
                    <p>Description 3</p>
                </a>
            </li>
        </ul>
    </div>
</div>

What I'd expect (and what I get in the grunt assemble build) is:

<div>
    <div class="is-open">
        <h3 id="subject-heading">Subject heading</h3>
        <ul id="content-subject-heading">
            <li>
                <a href="/url1">
                    <h4>Article title 1</h4>
                    <p>Description 1</p>
                </a>
            </li>
            <li>
                <a href="/url2">
                    <h4>Article title 2</h4>
                    <p>Description 2</p>
                </a>
            </li>
            <li>
                <a href="/url3">
                    <h4>Article title 3</h4>
                    <p>Description 3</p>
                </a>
            </li>
        </ul>
    </div>
</div>

{{#isnt @key "open"}} seems to be causing the problem. If I remove this from the second loop, all titles, urls and the description are ok, but then I get 'open' as list item which I don't want.

This may be a case of having to restructure the data in the hbs file, but there's a few so I'd like to avoid that if possible.

@shalvah
Copy link

shalvah commented Nov 10, 2019

This may be related. The context changes within these helpers. Quite unexpected.: #309 (comment)

@rgwebcode
Copy link

rgwebcode commented Aug 16, 2021

Did anyone ever find a solution for this?
I also cannot seem to use {{is @key data.user.status}} some text {{/is}} for example. There's no error thrown, but the text doesn't display correctly either.

Scratch this, I forgot to reference the global variable with ../data.user.status, then the comparison worked just fine.

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

3 participants