1

I was following with along the Ember Guides: Defining Your Routes and added a customized index route in my Ember app; which sets a controller title property:

// app/routes/index.js
import Ember from 'ember';

export default Ember.Route.extend({
  setupController: function(controller) {
    // Set the IndexController's `title`
    controller.set('title', 'Tagged! - home');
  }
});

I then added an output for the title in app/index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>{{title}}</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {{content-for 'head'}}

    <link rel="stylesheet" href="assets/vendor.css">
    <link rel="stylesheet" href="assets/tagged-ember.css">

    {{content-for 'head-footer'}}
  </head>
  <body>
    {{content-for 'body'}}

    <script src="assets/vendor.js"></script>
    <script src="assets/tagged-ember.js"></script>

    {{content-for 'body-footer'}}
  </body>
</html>

However instead of the expected output I get {{title}} in the browser title bar. Why is HTMLbars not outputting the variable?

I'm using the ember-cli (ember 1.13.3) and running the server with ember server. I can see the controller property in the ember inspector.

max
  • 96,212
  • 14
  • 104
  • 165

1 Answers1

1

The index.html file is outside the scope of the application controller/route/template, ember-cli-document-title solves the issue for you.

If you don't want to use it you can create an in-repo-addon that makes use of something like {{content-for 'document-title'}}.

Patsy Issa
  • 11,113
  • 4
  • 55
  • 74
  • That kind of makes sense, is this just a case of Embers crazy speed of development outrunning the docs? – max Jul 17 '15 at 09:08
  • The docs are up to par (in a way), this is not anything new and is a common functionality people look for, the thing is the application controller can't output anything outside of the application template `application.hbs` and the application template is included in the index via the `{{content-for 'body'}}` tag. – Patsy Issa Jul 17 '15 at 09:13
  • Thats just silly - docs should have examples which actually work. Thanks. – max Jul 17 '15 at 10:44
  • 1
    What you are trying to do and what is mentioned in the guide are 2 very different things, the guides are correct, they are setting a title inside the page, you are going for the `` tag, there is no mention of that in the guide. – Patsy Issa Jul 17 '15 at 10:46
  • Oops, I really missread that - in the guide they are printing it out in a `

    ` tag

    – max Jul 17 '15 at 10:46