Repository navigation
Conversation
|
Chatted with Jessica and she is ok with me using her name in an example :) |
|
|
||
| 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.
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.
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.
app/templates/application.hbs -> src/ui/routes/application/template.hbs
| 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.
app/controllers/application.hbs -> src/ui/routes/application/controller.js
| in the Component's JavaScript are available for use in the Template: | ||
|
|
||
| ### Helpers | ||
| ```javascript {data-filename=app/components/my-component.js} |
There was a problem hiding this comment.
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.
app/helpers/sum.js -> src/ui/components/sum.js
| 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.
app/templates/application.hbs -> src/routes/application/template.hbs
| 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.
app/templates/application.hbs -> src/routes/application/template.hbs
| Ember templates have some superpowers, but let's start with regular HTML. For any file in an Ember app that has an extension ending in `.hbs`, you can write HTML markup in it as if it was an `.html` file. HTML is the language that browsers understand for laying out content on a web page. `.hbs` stands for Handlebars, the name of a tool that lets you write more than just HTML in your templates. | ||
|
|
||
| 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.
application.hbs --> src/ui/routes/application/application.hbs
There was a problem hiding this comment.
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! |
locks
left a comment
There was a problem hiding this comment.
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.
"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.
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.
I think this will be super confusing and could be removed.
There was a problem hiding this comment.
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.
I want to split this out ssooo bad.
| Ember templates have some superpowers, but let's start with regular HTML. For any file in an Ember app that has an extension ending in `.hbs`, you can write HTML markup in it as if it was an `.html` file. HTML is the language that browsers understand for laying out content on a web page. `.hbs` stands for Handlebars, the name of a tool that lets you write more than just HTML in your templates. | ||
|
|
||
| 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.
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.
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