Skip to content

Commit f8f9d02

Browse files
committed
Converting more quick-start page content to use template tag
1 parent b974634 commit f8f9d02

File tree

1 file changed

+104
-3
lines changed

1 file changed

+104
-3
lines changed

guides/release/getting-started/quick-start.md

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ ember generate route scientists
135135

136136
You'll see output like this:
137137

138+
<feature-flag-off-template-tag>
138139
```text
139140
installing route
140141
create app/routes/scientists.js
@@ -144,6 +145,20 @@ updating router
144145
installing route-test
145146
create tests/unit/routes/scientists-test.js
146147
```
148+
</feature-flag-off-template-tag>
149+
<feature-flag-on-template-tag>
150+
```bash
151+
# 🚧 Under construction 🚧
152+
# `ember generate route` has not been updated to produce GJS files yet.
153+
installing route
154+
create app/routes/scientists.js
155+
create app/templates/scientists.gjs
156+
updating router
157+
add route scientists
158+
installing route-test
159+
create tests/unit/routes/scientists-test.js
160+
```
161+
</feature-flag-on-template-tag>
147162

148163
That is Ember telling you that it has created:
149164

@@ -152,6 +167,7 @@ That is Ember telling you that it has created:
152167
3. An entry in the application's router (located in `app/router.js`).
153168
4. A unit test for this route.
154169

170+
<feature-flag-off-template-tag>
155171
Open the newly-created template in `app/templates/scientists.hbs` and add the following HTML:
156172

157173
```handlebars {data-filename=app/templates/scientists.hbs}
@@ -162,6 +178,24 @@ Open the newly-created template in `app/templates/scientists.hbs` and add the fo
162178
In your browser, open [`http://localhost:4200/scientists`](http://localhost:4200/scientists).
163179
You should see the `<h2>` we put in the `scientists.hbs` template right below the `<h1>` from our `application.hbs` template.
164180

181+
</feature-flag-off-template-tag>
182+
<feature-flag-on-template-tag>
183+
Open the newly-created template in `app/templates/scientists.gjs` and add the following HTML:
184+
185+
```gjs {data-filename=app/templates/scientists.gjs}
186+
import { pageTitle } from 'ember-page-title';
187+
188+
<template>
189+
{{pageTitle "Scientists"}}
190+
<h2>List of Scientists</h2>
191+
</template>
192+
```
193+
194+
In your browser, open [`http://localhost:4200/scientists`](http://localhost:4200/scientists).
195+
You should see the `<h2>` we put in the `scientists.gjs` template right below the `<h1>` from our `application.gjs` template.
196+
197+
</feature-flag-on-template-tag>
198+
165199
Since the scientist route is nested under the application route, Ember will render its content inside the application route template's `{{outlet}}` directive.
166200

167201
Now that we've got the `scientists` template rendering,
@@ -191,6 +225,7 @@ the `model()` method supports any library that uses [JavaScript Promises](https:
191225
Now let's tell Ember how to turn that array of strings into HTML.
192226
Open the `scientists` template and add the following code to loop through the array and print it:
193227

228+
<feature-flag-off-template-tag>
194229
```handlebars {data-filename="app/templates/scientists.hbs"}
195230
<h2>List of Scientists</h2>
196231
@@ -200,6 +235,23 @@ Open the `scientists` template and add the following code to loop through the ar
200235
{{/each}}
201236
</ul>
202237
```
238+
</feature-flag-off-template-tag>
239+
240+
<feature-flag-on-template-tag>
241+
```gjs {data-filename="app/templates/scientists.gjs"}
242+
import { pageTitle } from 'ember-page-title';
243+
244+
<template>
245+
{{pageTitle "Scientists"}}
246+
<h2>List of Scientists</h2>
247+
<ul>
248+
{{#each @model as |scientist|}}
249+
<li>{{scientist}}</li>
250+
{{/each}}
251+
</ul>
252+
</template>
253+
```
254+
</feature-flag-on-template-tag>
203255

204256
Here, we use the `each` _helper_ to loop over each item in the array we
205257
provided from the `model()` hook. Ember will render the _block_ contained
@@ -217,16 +269,21 @@ As your application grows, you will notice you are sharing UI elements between m
217269
or using them multiple times on the same page.
218270
Ember makes it easy to refactor your templates into reusable components.
219271

220-
Let's create a `<PeopleList>` component that we can use in multiple places to show a list of people.
272+
Let's create a `PeopleList` component that we can use in multiple places to show a list of people.
221273

222274
As usual, there's a generator that makes this easy for us.
223275
Make a new component by typing:
224276

225277
```bash
278+
<feature-flag-on-template-tag>
279+
# 🚧 Under construction 🚧
280+
# `ember generate component` has not been updated to produce GJS files yet.
281+
</feature-flag-on-template-tag>
226282
ember generate component people-list
227283
```
228284

229-
Copy and paste the `scientists` template into the `<PeopleList>` component's template and edit it to look as follows:
285+
<feature-flag-off-template-tag>
286+
Copy and paste the `scientists` template into the `PeopleList` component's template and edit it to look as follows:
230287

231288
```handlebars {data-filename=app/components/people-list.hbs}
232289
<h2>{{@title}}</h2>
@@ -238,6 +295,25 @@ Copy and paste the `scientists` template into the `<PeopleList>` component's tem
238295
</ul>
239296
```
240297

298+
</feature-flag-off-template-tag>
299+
300+
<feature-flag-on-template-tag>
301+
Copy and paste this part of the `scientists` template into the `PeopleList` component and edit it to look as follows:
302+
303+
```gjs {data-filename=app/components/people-list.gjs}
304+
<template>
305+
<h2>{{@title}}</h2>
306+
307+
<ul>
308+
{{#each @people as |person|}}
309+
<li>{{person}}</li>
310+
{{/each}}
311+
</ul>
312+
</template>
313+
```
314+
315+
</feature-flag-on-template-tag>
316+
241317
Note that we've changed the title from a hard-coded string ("List of Scientists")
242318
to `{{@title}}`. The `@` indicates that `@title` is an argument that will be
243319
passed into the component, which makes it easier to reuse the same component in
@@ -246,7 +322,8 @@ other parts of the app we are building.
246322
We've also renamed `scientist` to the more-generic `person`,
247323
decreasing the coupling of our component to where it's used.
248324

249-
Our component is called `<PeopleList>`, based on its name on the file system. Please note that the letters P and L are capitalized.
325+
<feature-flag-off-template-tag>
326+
Our component is called `PeopleList`, based on its name on the file system. Please note that the letters P and L are capitalized.
250327

251328
<div class="cta">
252329
<div class="cta-note">
@@ -261,6 +338,7 @@ Our component is called `<PeopleList>`, based on its name on the file system. Pl
261338
<img src="/images/mascots/zoey.png" role="presentation" alt="">
262339
</div>
263340
</div>
341+
</feature-flag-off-template-tag>
264342

265343
Save this template and switch back to the `scientists` template.
266344

@@ -276,6 +354,7 @@ In the rest of the code examples in this tutorial, whenever we add or remove cod
276354

277355
Let's replace all our old code with our new componentized version:
278356

357+
<feature-flag-off-template-tag>
279358
```handlebars {data-filename="app/templates/scientists.hbs" data-diff="-1,-2,-3,-4,-5,-6,-7,+8,+9,+10,+11"}
280359
<h2>List of Scientists</h2>
281360
@@ -289,6 +368,28 @@ Let's replace all our old code with our new componentized version:
289368
@people={{@model}}
290369
/>
291370
```
371+
</feature-flag-off-template-tag>
372+
373+
<feature-flag-on-template-tag>
374+
```gjs {data-filename="app/templates/scientists.gjs" data-diff="+2,-6,-7,-8,-9,-10,-11,+12,+13,+14,+15"}
375+
import { pageTitle } from 'ember-page-title';
376+
import PeopleList from '../components/people-list';
377+
378+
<template>
379+
{{pageTitle "Scientists"}}
380+
<h2>List of Scientists</h2>
381+
<ul>
382+
{{#each @model as |scientist|}}
383+
<li>{{scientist}}</li>
384+
{{/each}}
385+
</ul>
386+
<PeopleList
387+
@title="List of Scientists"
388+
@people={{@model}}
389+
/>
390+
</template>
391+
```
392+
</feature-flag-on-template-tag>
292393

293394
Go back to your browser and you should see that the UI looks identical.
294395
The only difference is that now we've componentized our list into a version that's more reusable and more maintainable.

0 commit comments

Comments
 (0)