在过去的一个月里,我一直在使用Yeoman ember生成器,现在,我想尝试一下ember-cli。
我运行生成器并启动应用程序,一切工作正常。
ember new my-new-app
ember server但我想知道如何
{{content-for 'head'}}在app/index.html中工作吗?
当查看来自http://www.ember-cli.com/#tutorials的其他示例时,它们都没有使用这个特定的帮助程序?是因为他们使用的是旧版本的ember-cli吗?为什么他们不把这个内容用来做帮手呢?
我很确定ember.js没有这个内容--默认的帮助程序,所以我猜ember-cli是在什么地方写的?它在哪里?它是做什么用的?
另外,当我检查我的-Ember.js-app页面的元素时,'Welcome to Ember.js‘的div标签出现在body标签而不是head标签上?怎么可能?{{惊天}}
(在app/index.html中,{{content-for ' head '}}放在head标签内)
发布于 2014-10-07 04:48:45
它最近被添加到基于this discussion的ember-cli中。
下面是来自commit的相关代码
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('\n');
};发布于 2015-07-10 01:31:18
来自Ember CLI guide
app/index.html
app/index.html文件为应用程序奠定了基础。这里布置了基本的DOM结构,设置了title属性,并完成了样式表/javascript包含。除此之外,app/index.html还包括多个钩子-- {{content-for 'head'}}和{{content-for 'body'}} --插件可以使用它们将内容注入到应用程序的head或body中。您的应用程序需要保留这些钩子才能正常工作,但除非您直接使用特定的插件,否则可以安全地忽略它们。
我实际上是在寻找Welcome to Ember.js是从哪里来的(显然是在app\templates\application.hbs中),但首先偶然发现了content-for助手。
https://stackoverflow.com/questions/26210367
复制相似问题