Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
647 views
in Technique[技术] by (71.8m points)

ember.js - {{content-for 'head'}} 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

but I'd like to know how does

{{content-for 'head'}}

in app/index.html works?

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?

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?

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}}

( in app/index.html, {{content-for 'head'}} is placed inside head tag)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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('
');
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...