-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
New Templates intro #477
New Templates intro #477
Conversation
Chatted with Jessica and she is ok with me using her name in an example :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenweber I reviewed and suggested the required changes for the Octane/MU layout.
Please, let me know if you have any question.
|
||
You cannot use script tags directly within a template, and should use [actions]() or [Route Lifecycle Hooks]() to make your app responsive to user interactions and new data. If you are working with a non-Ember JavaScript library and need to use a `js` file from it, see the Guide section [Addons and Dependencies](). | ||
|
||
Similarly, you should not add links to CSS Stylesheets within the `hbs` file. Style rules should go in the `app/styles` directory instead. `app/styles/app.css` is included in your app's build by default. For CSS files within the styles directory, you can create multiple stylesheets and use regular CSS APIs like `import` to link them together. If you want to incorporate CSS from an npm package or similar, see [Addons and Dependencies]() for instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In MU/Octane layout:
app/styles
-> src/ui/styles
app/styles/app.css
-> src/ui/styles/app.css
|
||
The most common customizations developers make to `index.html` are when they use a CDN to load assets like fonts or stylesheets. Here's an example: | ||
|
||
```html {data-filename=app/index.html} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/index.html
-> src/ui/index.html
by putting them inside of curly braces, plus the word | ||
`this`: | ||
|
||
```handlebars {data-filename=app/templates/application.hbs} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/templates/application.hbs
-> src/ui/routes/application/template.hbs
To provide a `firstName` and `lastName` to the above template, properties | ||
must be added to the application controller. If you are following along with | ||
an Ember CLI application, you may need to create this file: | ||
A Template only has access to the data it has been given. This is referred to as the Template's "context." For example, to display a property inside a Route's Template, it should be defined in a Controller: | ||
|
||
```javascript {data-filename=app/controllers/application.js} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/controllers/application.hbs
-> src/ui/routes/application/controller.js
|
||
### Helpers | ||
```javascript {data-filename=app/components/my-component.js} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/components/my-component.js
-> src/ui/components/my-component/component.js
Ember gives you the ability to [write your own helpers](../writing-helpers/), and comes with some [helpers built-in](). | ||
|
||
For example, let's say you would like the ability to add two numbers together. | ||
Define a function in `app/helpers/sum.js` to create a `sum` helper: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/helpers/sum.js
-> src/ui/components/sum.js
}; | ||
|
||
export default helper(sum); | ||
``` | ||
|
||
The above code will allow you invoke the `sum()` function as a `{{sum}}` handlebars "helper" in your templates: | ||
Now you can use the `sum()` function as `{{sum}}` in your templates: | ||
|
||
```handlebars {data-filename=app/templates/application.hbs} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/templates/application.hbs
-> src/routes/application/template.hbs
Sometimes, you might see helpers used inside of some parentheses, `()`. | ||
It means that a Helper is being used inside of another Helper or Component. | ||
This is referred to as a "nested" Helper. | ||
Parentheses must be used because curly braces `{{}}` cannot be nested. | ||
|
||
```handlebars {data-filename=app/templates/application.hbs} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/templates/application.hbs
-> src/routes/application/template.hbs
|
||
For example, this `application.hbs` template will render a first and last name: | ||
For example, every Ember app has a file called `application.hbs`. You can write regular HTML markup there or in any other `hbs` file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
application.hbs
--> src/ui/routes/application/application.hbs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd make sense to keep the phrasing, but add "(located at: )"
@ppcano thanks for your input, but I believe this is targetting master and not octane on purpose! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not fond of the capitalized Template throughout the prose 😅 .
Some small tweaks and questions heading your way!
|
||
## Making new Templates | ||
|
||
New templates should be made using the [Ember CLI](https://cli.emberjs.com). It helps ensure that the files go in the right place in the app folder structure, and that they follow the right file naming conventions. If you have never used the Ember CLI before, it is recommended to do the [Tutorial](). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"should" seems a bit strong because of the fact that the commands generate other files than the template.
Why not mention the ember generate template
command?
|
||
You cannot use script tags directly within a template, and should use [actions]() or [Route Lifecycle Hooks]() to make your app responsive to user interactions and new data. If you are working with a non-Ember JavaScript library and need to use a `js` file from it, see the Guide section [Addons and Dependencies](). | ||
|
||
Similarly, you should not add links to CSS Stylesheets within the `hbs` file. Style rules should go in the `app/styles` directory instead. `app/styles/app.css` is included in your app's build by default. For CSS files within the styles directory, you can create multiple stylesheets and use regular CSS APIs like `import` to link them together. If you want to incorporate CSS from an npm package or similar, see [Addons and Dependencies]() for instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my kingdom for a styling section 😂
{{yield}} | ||
``` | ||
|
||
Lastly, it's important to know that data can be passed from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will be super confusing and could be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure this should be explained quite like this. I wonder how React introduces props
🤔 I think this should be explained as arguments from the get go though. Maybe we can add a hand-wavey explanation of Component above to introduce the concept of arguments?
|
||
Learn more about passing data between Templates in [../../components/passing-properties-to-a-component]. | ||
|
||
## Helper functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to split this out ssooo bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really great so far! Sorry for the late review, but thanks for putting this together @jenweber, I really love the tone so far
|
||
For example, this `application.hbs` template will render a first and last name: | ||
For example, every Ember app has a file called `application.hbs`. You can write regular HTML markup there or in any other `hbs` file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd make sense to keep the phrasing, but add "(located at: )"
{{yield}} | ||
``` | ||
|
||
Lastly, it's important to know that data can be passed from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure this should be explained quite like this. I wonder how React introduces props
🤔 I think this should be explained as arguments from the get go though. Maybe we can add a hand-wavey explanation of Component above to introduce the concept of arguments?
A few changes I made:
|
P.S. Thanks everyone for your careful reviews ❤️ |
All issues addressed, and have been reviewed again
* Rough draft of new Templates intro * update helper to buildHelper * lowercase Template --> template * the compiler is your friend * one template to one hundred templates * correct route lifecycle to components, add ember generate command * apply feedback * fix links, more linting, code block spacing
This is a rough draft that should not be merged yet. It is for evaluating what, if any, of this content could come into the Guides.
This PR partially addresses #460