Skip to content

Undefined data in one partial but not another #164

@dwilt

Description

@dwilt

I have 3 partials and 1 data file which are part of the problem.

buttons.json

{
    "showAll": {
        "element": "a",
        "href": "-",
        "text": "Show All"
    },
    "greenFlatSubmit": {
        "element": "button",
        "type": "submit",
        "text": "Submit",
        "color": "green",
        "style": "flat"
    },
    "greenFlatCancel": {
        "element": "button",
        "type": "cancel",
        "text": "Cancel",
        "color": "green",
        "style": "flat"
    }
}

button.hbs

<{{ element }}{{#is element "a"}} href="{{ href }}"{{/is }}{{#if type }} type="{{ type }}"{{/if }} class="bd-button{{#if color }} bd-{{color}}{{/if }}{{#if style }} bd-{{style}}{{/if }}">{{ text }}</{{ element }}>

show-all-button.hbs

<div class="bd-button-container bd-show-all">
    {{>button buttons.showAll }}
</div>

leave-comment-form.hbs

<form class="bd-leave-comment-form" action="#">
    <div class="bd-container bd-user-photo">
        {{>user-photo }}
    </div>
    <div class="bd-container bd-user-message">
        <div class="bd-field">
            <label class="bd-textarea-label" for="">Leave a comment</label>
            <textarea name="#" id="" placeholder="Leave a comment"></textarea>
        </div>
        {{>button buttons.greenFlatSubmit }}
        {{>button buttons.greenFlatCancel }}
    </div>
</form>

Basically, what I have going on here is that I have 2 partials (show-all-button and leave-comment-form) which are including the button partial and passing in data from the buttons JSON file. When I try to grunt, I'm getting an error saying:

Warning: Cannot read property 'element' of undefined Use --force to continue.

So, I removed both button partial calls from both files and I put some logging info at the top of leave-comment-form.hbs:

{{ log "leave-comment-form.hbs" }}
{{ log buttons }}

And when I grunt, I get this:

leave-comment-form.hbs
{ showAll: { element: 'a', href: '-', text: 'Show All' },
  greenFlatSubmit: 
   { element: 'button',
     type: 'submit',
     text: 'Submit',
     color: 'green',
     style: 'flat' },
  greenFlatCancel: 
   { element: 'button',
     type: 'cancel',
     text: 'Cancel',
     color: 'green',
     style: 'flat' } }

So that's good. We know that the leave-comment-form.hbs partial is getting the buttons.json. But when I remove the logging from the top of leave-comment-form.hbs and put it into show-all-button.hbs, I get this error:

show-all-button.hbs
undefined
show-all-button.hbs
{ showAll: { element: 'a', href: '-', text: 'Show All' },
  greenFlatSubmit: 
   { element: 'button',
     type: 'submit',
     text: 'Submit',
     color: 'green',
     style: 'flat' },
  greenFlatCancel: 
   { element: 'button',
     type: 'cancel',
     text: 'Cancel',
     color: 'green',
     style: 'flat' } }

show-all-button is getting called in two places from two different templates. Obviously buttons.json is available to the partial at one of the calls in the one file but not the other one. How could the data only be available to one partial call if it's global data?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions