我最近将节点刀片式智能包添加到我的流星,并且静态内容显示正常。但是,我无法使用任何模板变量。在安装刀片之前,模板变量在车把上工作正常。有人知道我做错了吗?
ReferenceError: player is not defined
at ~/meteor/project/views/info.blade:1:1
1 > .player-name.large= player.name
2 | .alliance-name= alliance.name
3 | .world-name= world.name
4 |
at eval (eval at <anonymous> (/usr/local/lib/node_modules/blade/lib/compiler.js:138:23))
at /usr/local/lib/node_modules/blade/lib/runtime.js:323:5
at runtime.loadTemplate (/usr/local/lib/node_modules/blade/lib/runtime.js:272:6)
at /usr/local/lib/node_modules/blade/lib/blade.js:45:4
at Compiler.compile (/usr/local/lib/node_modules/blade/lib/compiler.js:185:2)
at compile (/usr/local/lib/node_modules/blade/lib/blade.js:41:12)
at Object.compileFile (/usr/local/lib/node_modules/blade/lib/blade.js:66:3)
at Object.runtime.loadTemplate (/usr/local/lib/node_modules/blade/lib/runtime.js:269:23)
at Object.runtime.include (/usr/local/lib/node_modules/blade/lib/runtime.js:320:22)
at eval (eval at <anonymous> (/usr/local/lib/node_modules/blade/lib/compiler.js:138:23))
Your application is crashing. Waiting for file change.
.player-name.large= player.name
if(Meteor.is_client) {
Template.info.player = function(){
var data = Session.get( 'data' );
return data.player;
};
}
答案 0 :(得分:3)
编辑:现在允许在正文模板中使用助手。
您不能在head 或body 模板中使用帮助器或某些全局变量。您甚至无法在head 或body 模板中包含的模板中使用它们。
查看这些链接以获取更多信息:
答案 1 :(得分:2)
编辑:从Blade 3.0.0开始,此答案不再准确。 body.blade
模板可能不包含助手,Session
的引用等动态内容。
头部或身体模板中不允许引用Session。这是设计的,它不是一个bug。在Handlebars中,您可以在标记内使用Session或Meteor,但不能使用标记。我不喜欢Handlebars的实现,所以你坚持这个。 body.blade模板主要用于静态内容(即加载页面或其他任何内容)。加载应用程序后,您可以执行
$("body").replaceWith(Meteor.ui.render(Template.homepage) )
;来自您的应用程序代码。
所以,这就是说,在初始化时,人们无法拥有动态生成的模板。
要解决此问题,文档建议
$("body").replaceWith(Meteor.ui.render(Template.homepage) )
我用replaceWith
方法替换了html
方法。看一个适合我的例子:
# ./the_cow.coffee
if Meteor.isClient
$ ->
$('body').html Meteor.render -> Template.test
user:
name: 'Pill'
# ./views/test.blade
#test Testing
p= user.name
查看已编译的JavaScript:
if (Meteor.isClient) {
$(function() {
return $('body').html(Meteor.render(function() {
return Template.test({
user: {
name: 'Pill'
}
});
}));
});
}
不知道是否有更短的写作方式。