-
-
Notifications
You must be signed in to change notification settings - Fork 520
use gjs in Linking Between Routes guide #2175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,17 @@ Router.map(function() { | |
| }); | ||
| ``` | ||
|
|
||
| ```handlebars {data-filename=app/templates/photos.hbs} | ||
| <ul> | ||
| {{#each this.photos as |p|}} | ||
| <li> | ||
| <LinkTo @route="photos.edit" @model={{p}}>{{p.title}}</LinkTo> | ||
| </li> | ||
| {{/each}} | ||
| </ul> | ||
| ```handlebars {data-filename=app/templates/photos.gjs} | ||
| import { LinkTo } from '@ember/routing'; | ||
| <template> | ||
| <ul> | ||
| {{#each this.photos as |p|}} | ||
| <li> | ||
| <LinkTo @route="photos.edit" @model={{p}}>{{p.title}}</LinkTo> | ||
| </li> | ||
| {{/each}} | ||
| </ul> | ||
| </template> | ||
| ``` | ||
|
|
||
| The `@route` argument is the name of the route to link to, and the `@model` | ||
|
|
@@ -56,7 +59,7 @@ behavior can be customized within `PhotoEditRoute`'s `serialize` hook. | |
| Alternatively, you can explicitly provide a serialized `id`, in place of | ||
| passing a model object: | ||
|
|
||
| ```handlebars {data-filename=app/templates/photos.hbs} | ||
| ```handlebars {data-filename=app/templates/photos.gjs} | ||
| <LinkTo @route="photos.edit" @model="1">First Photo Ever</LinkTo> | ||
| ``` | ||
|
|
||
|
|
@@ -93,14 +96,17 @@ will be given the `active` CSS class. For example, if you were at the URL | |
|
|
||
| The CSS class name used for active classes can be customized for a single use of `<LinkTo />` by passing an `@activeClass` argument: | ||
|
|
||
| ```handlebars {data-filename=app/templates/photos.hbs} | ||
| <ul> | ||
| {{#each this.photos as |p|}} | ||
| <li> | ||
| <LinkTo @route="photos.edit" @model={{p}} @activeClass="font-bold">{{p.title}}</LinkTo> | ||
| </li> | ||
| {{/each}} | ||
| </ul> | ||
| ```handlebars {data-filename=app/templates/photos.gjs} | ||
| import { LinkTo } from '@ember/routing'; | ||
| <template> | ||
| <ul> | ||
| {{#each this.photos as |p|}} | ||
| <li> | ||
| <LinkTo @route="photos.edit" @model={{p}} @activeClass="font-bold">{{p.title}}</LinkTo> | ||
| </li> | ||
| {{/each}} | ||
| </ul> | ||
| </template> | ||
| ``` | ||
|
|
||
| will result in: | ||
|
|
@@ -146,12 +152,15 @@ URL. | |
|
|
||
| For example, if we are currently on `/photos/2`, then the following template: | ||
|
|
||
| ```handlebars {data-filename=app/templates/photos/photo.hbs} | ||
| {{#each this.photo.comments as |comment|}} | ||
| <LinkTo @route="photos.photo.comment" @model={{comment}}> | ||
| {{excerpt comment.body}}... | ||
| </LinkTo> | ||
| {{/each}} | ||
| ```handlebars {data-filename=app/templates/photos/photo.gjs} | ||
| import { LinkTo } from '@ember/routing'; | ||
| <template> | ||
| {{#each this.photo.comments as |comment|}} | ||
| <LinkTo @route="photos.photo.comment" @model={{comment}}> | ||
| {{excerpt comment.body}}... | ||
| </LinkTo> | ||
| {{/each}} | ||
| </template> | ||
| ``` | ||
|
|
||
| ...will render something like this: | ||
|
|
@@ -182,18 +191,21 @@ To solve this problem, or maybe to cross-link comments from photos other than | |
| the currently active one, you can pass an array of model objects using the | ||
| `@models` argument and the `{{array}}` helper: | ||
|
|
||
| ```handlebars {data-filename=app/templates/photos.hbs} | ||
| <h1>Latest Comments</h1> | ||
|
|
||
| <ul> | ||
| {{#each this.latestComments as |comment|}} | ||
| <li> | ||
| <LinkTo @route="photos.photo.comment" @models={{array comment.photo comment}}> | ||
| {{excerpt comment.body}}... | ||
| </LinkTo> | ||
| </li> | ||
| {{/each}} | ||
| </ul> | ||
| ```handlebars {data-filename=app/templates/photos.gjs} | ||
| import { LinkTo } from '@ember/routing'; | ||
| <template> | ||
| <h1>Latest Comments</h1> | ||
|
|
||
| <ul> | ||
| {{#each this.latestComments as |comment|}} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very good point 👍 yes that would need to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, it probably applies to the other references to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was just going to suggest that you look at all the Additionally, you will need to add import statements for everything you use in the template, like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well just to be clear here, until you explicitly added the file name this template wasn't technically wrong. You had "plausable denyability" that you were dealing with a component or something (although there was no backing class so the argument is very weak). If you want to be 100% correct there should be a backing class that shows some I hope all that makes sense
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback! I think I know what to do, I'm working on addressing this now then I'll ask for more feedback.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to write a backing class in the template or assume that latestComments came from a controller and just use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate controllers, so I'm a fan of using the stateful component pattern instead of controller lol
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I guess we don't necessarily need to indrectly encourage controller use here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a backing class version, although we had some discussion about longer term direction in the discord. https://discord.com/channels/480462759797063690/480777444203429888/1432054589661778003 |
||
| <li> | ||
| <LinkTo @route="photos.photo.comment" @models={{array comment.photo comment}}> | ||
| {{excerpt comment.body}}... | ||
| </LinkTo> | ||
| </li> | ||
| {{/each}} | ||
| </ul> | ||
| </template> | ||
| ``` | ||
|
|
||
| Here, we are passing an array of model objects (the photo, then the comment), | ||
|
|
@@ -224,10 +236,13 @@ example, it is quite common to want to add additional CSS classes to the | |
| generated link tag, or specifying the appropriate ARIA attributes. You can | ||
| simply pass them along with the invocation: | ||
|
|
||
| ```handlebars {data-filename=app/templates/photos/edit.hbs} | ||
| <LinkTo @route="photos" class="btn btn-primary" role="button" aria-pressed="false"> | ||
| Discard Changes | ||
| </LinkTo> | ||
| ```handlebars {data-filename=app/templates/photos/edit.gjs} | ||
| import { LinkTo } from '@ember/routing'; | ||
| <template> | ||
| <LinkTo @route="photos" class="btn btn-primary" role="button" aria-pressed="false"> | ||
| Discard Changes | ||
| </LinkTo> | ||
| </template> | ||
| ``` | ||
|
|
||
| CSS classes passed this way will be _in addition to_ the standard `ember-view` | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.