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

weird issue with blocks #8

Closed
mbouclas opened this issue Oct 14, 2014 · 3 comments
Closed

weird issue with blocks #8

mbouclas opened this issue Oct 14, 2014 · 3 comments
Milestone

Comments

@mbouclas
Copy link

super simple scenario, works without express (by doing a manual compile and template()) but when using res.render i get the following error :

TypeError: /media/sf_work/testing/partial/App/views/partials/dashboard.hbs: Cannot read property 'body' of undefined
   at getBlocks (/media/sf_work/testing/partial/node_modules/handlebars-layouts/index.js:6:18)
   at Object.handlebars.registerHelper.block (/media/sf_work/testing/partial/node_modules/handlebars-layouts/index.js:59:26)
   at Object.eval (eval at <anonymous> (/media/sf_work/testing/partial/node_modules/hbs/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:189:23), <anonymous>:13:161)
   at /media/sf_work/testing/partial/node_modules/hbs/node_modules/handlebars/dist/cjs/handlebars/runtime.js:86:31
   at /media/sf_work/testing/partial/node_modules/hbs/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:465:21
   at /media/sf_work/testing/partial/node_modules/hbs/lib/hbs.js:80:17
   at /media/sf_work/testing/partial/node_modules/hbs/lib/hbs.js:61:11
   at Function.Waiter.done (/media/sf_work/testing/partial/node_modules/hbs/lib/async.js:60:16)
   at /media/sf_work/testing/partial/node_modules/hbs/lib/hbs.js:56:15
   at fs.js:266:14

Layout :

<div id="wrapper">
    {{#block "body"}}

    {{/block}}
</div>

partial :

{{#extend "layout"}}
    {{#append "body"}}
asdasdasd
    {{/append}}
{{/extend}}

Like i mentioned earlier, when doing

app.get('/' ,function (req, res) {
  res.render('partials/dashboard',{
    include_file : 'index',
    location : 'home'
  });
});

i get the above error. If i do a

      hbs.registerPartial('layout', fs.readFileSync(__dirname + '/views/layout.hbs', 'utf8'))
        var template = hbs.compile(hbs,handlebars.partials['partials/dashboard']);


app.get('/' ,function (req, res) {
  res.send(template({
            title: 'Layout Test',
            items: [
                'apple',
                'orange',
                'banana'
            ]
        }));
});

works like a charm, i get the correct output. One weird thing i noticed is that on the Express scenario, doing a console.log in the getBlocks function of the var blocks i get the following output

{}
{ body: [ { should: 'append', fn: [Object] } ] }
undefined

catching the undefined solved the error but the partial is not added to the layout.
I am using the 0.3.3 version and 4.8.8 of express

Any help would be most welcomed at this point.

@shannonmoeller
Copy link
Owner

Thanks for submitting this issue. I'll be looking into Express compatibility issues shortly. My first task is to setup a proper test case.

@shannonmoeller shannonmoeller added this to the 1.0.0 milestone Oct 20, 2014
@shannonmoeller
Copy link
Owner

I've added a test case to the deep-inheritance feature branch and it's working flawlessly for me. Can you take a look?

https://github.com/shannonmoeller/handlebars-layouts/blob/f35bf3597da148b269b41989d6be4e5349ee4a78/test/express.js?ts=4

@shannonmoeller
Copy link
Owner

Version 1.0.0 released.

Repository owner locked and limited conversation to collaborators Apr 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants