Skip to content

Commit d00a29e

Browse files
committed
Documented use of ember-cli-head in Octane
1 parent fd6f33a commit d00a29e

1 file changed

Lines changed: 26 additions & 35 deletions

File tree

README.md

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Install by running
2323
ember install ember-cli-head
2424
```
2525

26-
And add `{{head-layout}}` to the top of your application template.
26+
And add `<HeadLayout />` to the top of your application template.
2727

2828
#### Version
2929
Take into account that version >= 0.3 of this addon require Ember 2.10+ and fastboot >=1.0.rc1
@@ -51,30 +51,33 @@ model is actually an alias for the `head-data` service. You can set
5151
whatever data you want to be available in the template directly on
5252
that service.
5353

54+
⚠️ Warning for Octane apps:
55+
56+
Because `model` refers to the `head-data` service (and not what a route's `model` hook returns), it is important to use `this.model` (not `@model`) in `app/templates/head.hbs`.
57+
5458
### Example
5559

5660
#### Setting content data in route
5761

5862
```javascript
5963
// app/routes/application.js
6064

61-
import Route from '@ember/routing/route'
62-
import { inject } from '@ember/service';
63-
import { set } from '@ember/object';
65+
import Route from '@ember/routing/route';
66+
import { inject as service } from '@ember/service';
67+
68+
export default class ApplicationRoute extends Route {
69+
@service headData;
6470

65-
export default Route.extend({
66-
// inject the head data service
67-
headData: inject(),
6871
afterModel() {
69-
set(this, 'headData.title', 'Demo App');
72+
this.headData.title = 'Demo App';
7073
}
71-
});
74+
}
7275
```
7376

7477
#### Using the service as model in head.hbs
7578

76-
```javascript
77-
<meta property="og:title" content={{model.title}} />
79+
```handlebars
80+
<meta property="og:title" content={{this.model.title}} />
7881
```
7982

8083
#### Resulting head
@@ -83,28 +86,14 @@ This will result in a document along the lines of:
8386

8487
```html
8588
<html data-ember-extension="1">
86-
<head>
87-
<meta charset="utf-8">
88-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
89-
<title>My Ember App</title>
90-
<meta name="description" content="">
91-
<meta name="viewport" content="width=device-width, initial-scale=1">
92-
93-
<base href="/">
94-
95-
<link rel="stylesheet" href="assets/vendor.css">
96-
<link rel="stylesheet" href="assets/my-app.css">
97-
89+
<head>
90+
...
91+
<meta name="ember-cli-head-start" content>
9892
<meta property="og:title" content="Demo App">
93+
<meta name="ember-cli-head-end" content>
9994
</head>
10095
<body class="ember-application">
101-
102-
103-
<script src="assets/vendor.js"></script>
104-
<script src="assets/my-app.js"></script>
105-
<div id="ember383" class="ember-view"><h2 id="title">Welcome to Ember</h2>
106-
107-
</div>
96+
...
10897
</body>
10998
</html>
11099
```
@@ -117,21 +106,23 @@ If you do not wish to have the head content "live" while running in browser you
117106

118107
```javascript
119108
module.exports = function(environment) {
120-
var ENV = {
109+
let ENV = {
121110
'ember-cli-head': {
122-
suppressBrowserRender: true
111+
suppressBrowserRender: true
123112
}
124113
};
125-
}
114+
115+
return ENV;
116+
};
126117
```
127118

128119
### Upgrade to 0.4.x
129120

130-
As mentioned above you need to add the `{{head-layout}}` component once and only once in an application wide template. This template is usually `app/templates/application.hbs`, but could be different in your case. Previously, in ember-cli-head 0.3.x and below the component was appended to the document inside an instance initializer. This prevented the need for the `{{head-layout}}` component as it was automatically injected and used inside that initializer. Unfortunately, this approach needed to change so that we could render the component with the rest of the application rendering.
121+
As mentioned above you need to add the `<HeadLayout />` component once and only once in an application wide template. This template is usually `app/templates/application.hbs`, but could be different in your case. Previously, in ember-cli-head 0.3.x and below the component was appended to the document inside an instance initializer. This prevented the need for the `<HeadLayout />` component as it was automatically injected and used inside that initializer. Unfortunately, this approach needed to change so that we could render the component with the rest of the application rendering.
131122

132123
If you care to read more about the details of render please see the PR that introduced these changes https://github.com/ronco/ember-cli-head/pull/37
133124

134-
But for now, if you are upgrading to 0.4.x, you simply need to add `{{head-layout}}` component to your application wide template.
125+
But for now, if you are upgrading to 0.4.x, you simply need to add `<HeadLayout />` component to your application wide template.
135126

136127
If you make use of this mode the content of `<head>` will be the static FastBoot rendered content through the life of your App.
137128

0 commit comments

Comments
 (0)