{{content-for'head'}} Ember-cli

Suk*_*ito 32 ember.js ember-cli

过去1个月我一直在使用Yeoman余烬发生器,现在,我想尝试一下ember-cli.

我运行生成器并启动应用程序,一切正常.

ember new my-new-app
ember server
Run Code Online (Sandbox Code Playgroud)

但我想知道怎么做

{{content-for 'head'}}
Run Code Online (Sandbox Code Playgroud)

在app/index.html中有效吗?

在查看http://www.ember-cli.com/#tutorials中的其他示例时,他们都没有使用这个特定的助手?是因为他们使用旧版本的ember-cli?他们为什么不使用这些内容作为助手呢?

我很确定ember.js没有这个内容 - 默认情况下是helper,所以我猜是ember-cli在某处写的?它在哪里以及它的用途是什么?

另外,当我检查my-new-app页面的元素时,"Welcome to Ember.js"的div标签出现在body标签而不是head标签上?怎么可能?{{心吹}}

(在app/index.html中,{{content-for'head'}}放在head标签内)

Pet*_*own 25

最近根据此讨论将其添加到ember-cli中.

以下是提交中的相关代码:

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');
};
Run Code Online (Sandbox Code Playgroud)

  • 有关其他一些上下文,请参阅https://www.npmjs.org/package/ember-cli-inline-content (2认同)

mp3*_*415 21

来自Ember CLI指南:

应用程序/ index.html的

app/index.html文件为您的应用程序奠定了基础.这是布局基本DOM结构,设置title属性并完成stylesheet/javascript包含的地方.除此之外,app/index.html还包括多个挂钩 - {{content-for 'head'}}{{content-for 'body'}}- 可以被Addons用来将内容注入您的应用程序headbody.这些挂钩需要保留在原位,以便您的应用程序正常运行,但除非您直接使用特定的插件,否则可以安全地忽略它们.

我实际上是在寻找来自哪里Welcome to Ember.js(显然是在app\templates\application.hbs),但首先偶然发现了content-for助手.