Handlebar Complex Data structure

Viewed 90

I have currently got multiple partials and they are using high level data structures. For each page, i have its own data structure, so i can get page specific and one component specific json structure.

full.json

{
    "paragraph":{
        "lorem": "blah blah blah"
    },
    "somethingelse":{
        "lorem": "blah blah"
    }
    "partialthree":{
        "lorem": "blah blah"
    }
    page_one: {
        "title": "blah blah",
        "somethingelse": {
            "lorem": "something completely different."
        }
    }    
}

comp/partial_one.hbs

{{#paragraph}}
    <p>{{lorem}}</p>
{{/paragraph}}

Output: <p>blah blah blah</p>

comp/partial_two.hbs

{{#somethingelse}}
    <div>{{lorem}}</div>
{{/somethingelse}}

Output: <div>blah blah</div>

comp/partial_three.hbs

{{#partialthree}}
    <p>{{lorem}}</p>
    {{> comp/partial_two }}
{{/partialthree}}

Output (note, partial_two didnt load due to the data structure is now partialthree.somethingelse (which doesnt exist): <p>blah blah</p>

page/page_one.hbs

{{#page_one}}
    {{> comp/partial_three }}
    <div>{{title}}</div>
    {{> comp/partial_two }}
{{/page_one}}

Output:

<div>blah blah</div>
<div>something completely different.</div>

Question: Is it possible for page_one and partial_three handlebar templates which have partials inside them to default if it cannot find the data.

Question: Is this the correct way of handling data in handlebar.

Note: I CANNOT CHANGE THE FULL.JSON STRUCTURE. ITS ALWAYS COMPONENTS AND THEN PAGES.

0 Answers
Related