{{content-for 'head'}} Ember-cli [英] {{content-for 'head'}} Ember-cli
问题描述
过去 1 个月我一直在使用 Yeoman 余烬生成器,现在,我想试试 ember-cli.
I've been using Yeoman ember generator for the past 1 month and now, I'd like to give ember-cli a try.
我运行生成器并启动应用程序,一切正常.
I run the generator and launch the app, everything works fine.
ember new my-new-app
ember server
但我想知道如何
{{content-for 'head'}}
在 app/index.html 中有效吗?
in app/index.html works?
查看来自 http://www.ember-cli.com/#tutorials 的其他示例时,他们都没有使用这个特殊的帮手?是不是因为他们使用的是旧版本的 ember-cli?他们为什么不使用这个 content-for 助手?
When looking at other examples from http://www.ember-cli.com/#tutorials, none of them are using this particular helper? Is it because they are using older version of ember-cli? Why weren't they using this content-for helper?
我很确定 ember.js 默认没有这个 content-for helper,所以我猜 ember-cli 写在某个地方?它在哪里,有什么用?
I'm pretty sure that ember.js doesn't have this content-for helper in default, so I'm guessing ember-cli wrote it somewhere? Where is it and what is it for?
另外,当我检查 my-new-app 页面的元素时,'Welcome to Ember.js' 的 div 标签出现在 body 标签而不是 head 标签?这怎么可能?{{脑洞大开}}
Also, when I inspect the element of my-new-app page, the div tag of 'Welcome to Ember.js' appeared at the body tag instead of head tag? How is that possible? {{mind-blown}}
(在 app/index.html 中,{{content-for 'head'}} 放在 head 标签内)
( in app/index.html, {{content-for 'head'}} is placed inside head tag)
推荐答案
最近基于 这个讨论.
这是提交的相关代码:
EmberApp.prototype.contentFor = function(config, match, type) {
var content = [];
if (type === 'head') {
content.push(calculateBaseTag(config));
content.push('<meta name="' + config.modulePrefix + '/config/environment" ' +
'content="' + escape(JSON.stringify(config)) + '">');
}
content = this.project.addons.reduce(function(content, addon) {
if (addon.contentFor) {
return content.concat(addon.contentFor(type, config));
}
return content;
}, content);
return content.join('
');
};
这篇关于{{content-for 'head'}} Ember-cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!