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

橙三吉。 提交于 2019-11-28 19:10:26

It was recently added to ember-cli based on this discussion.

Here is the relevant code from the 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');
};

From Ember CLI guide:

app/index.html

The app/index.html file lays the foundation for your application. This is where the basic DOM structure is laid out, the title attribute is set and stylesheet/javascript includes are done. In addition to this, app/index.html includes multiple hooks - {{content-for 'head'}} and {{content-for 'body'}} - that can be used by Addons to inject content into your application’s head or body. These hooks need to be left in place for your application to function properly, but they can be safely ignored unless you are working directly with a particular addon.

I was actually looking for where Welcome to Ember.jsis coming from (which is obviously in app\templates\application.hbs), but first stumbled upon content-for helpers.

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