Using Bladejs with Meteor

蹲街弑〆低调 提交于 2019-12-05 21:18:09

EDIT: Helpers are now permitted in body templates.

You cannot use helpers or certain global variables in head or body templates. You can't even use them in templates that are included by head or body templates.

Checkout these links for more information:

juanpastas

EDIT: This answer is no longer accurate as of Blade 3.0.0 stable. body.blade templates may not contain dynamic stuff like helpers, references to Session, etc.


In 'Using Blade with Meteor' says that

References to Session are not allowed in head or body templates. This is by design, and it is not a bug. In Handlebars, you could use Session or Meteor within a tag, but not a tag. I didn't like the Handlebars implementation, so you're stuck with this one. The body.blade template is mostly for static content (i.e. a loading page or whatever). Once your application is loaded, you can do $("body").replaceWith(Meteor.ui.render(Template.homepage) ); from your application code.

So, this is saying that, on initialization, one could not have dynamic generated templates.

To workaround this, documentation suggests

$("body").replaceWith(Meteor.ui.render(Template.homepage) )

I replaced replaceWith method with html method. See an example that's working for me:

# ./the_cow.coffee
if Meteor.isClient
  $ ->
    $('body').html Meteor.render -> Template.test
      user:
        name: 'Pill'

# ./views/test.blade
#test Testing
p= user.name

See the compiled JavaScript:

if (Meteor.isClient) {
  $(function() {
    return $('body').html(Meteor.render(function() {
      return Template.test({
        user: {
          name: 'Pill'
        }
      });
    }));
  });
}

Don't know if there is a shorter way to write it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!