Skip to content
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

Merged
merged 16 commits into from
Mar 7, 2019
Merged

New Templates intro #477

merged 16 commits into from
Mar 7, 2019

Conversation

jenweber
Copy link
Contributor

@jenweber jenweber commented Feb 18, 2019

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.

To make Templates work as the opening topic, additions are necessary in the introduction.

This PR partially addresses #460

@jenweber
Copy link
Contributor Author

Chatted with Jessica and she is ok with me using her name in an example :)

Copy link
Contributor

@ppcano ppcano left a 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.
Copy link
Contributor

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}
Copy link
Contributor

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}
Copy link
Contributor

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}
Copy link
Contributor

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}
Copy link
Contributor

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:
Copy link
Contributor

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}
Copy link
Contributor

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}
Copy link
Contributor

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

guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved

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:
Copy link
Contributor

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

Copy link
Contributor

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: )"

@locks
Copy link
Contributor

locks commented Feb 19, 2019

@ppcano thanks for your input, but I believe this is targetting master and not octane on purpose!

locks
locks previously requested changes Feb 19, 2019
Copy link
Contributor

@locks locks left a 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!

guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved
guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved

## 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]().
Copy link
Contributor

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?

guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved

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.
Copy link
Contributor

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 😂

guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved
guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved
{{yield}}
```

Lastly, it's important to know that data can be passed from
Copy link
Contributor

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.

Copy link
Contributor

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?

guides/release/templates/handlebars-basics.md Show resolved Hide resolved

Learn more about passing data between Templates in [../../components/passing-properties-to-a-component].

## Helper functions
Copy link
Contributor

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.

Copy link
Contributor

@pzuraq pzuraq left a 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

guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved

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:
Copy link
Contributor

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: )"

guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved
guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved
guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved
guides/release/templates/handlebars-basics.md Show resolved Hide resolved
{{yield}}
```

Lastly, it's important to know that data can be passed from
Copy link
Contributor

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?

guides/release/templates/handlebars-basics.md Outdated Show resolved Hide resolved
@pzuraq pzuraq mentioned this pull request Feb 20, 2019
2 tasks
@jenweber
Copy link
Contributor Author

jenweber commented Mar 7, 2019

A few changes I made:

  • nearly all of the above suggestions
  • un-capitalized "templates" since it's a generic term
  • Added a line break after every period
  • I cut the "passing data from a controller to a component" altogether, and just added a note about it
  • I simplified wording in a few places but it could use another pass, someday that is not now
  • And I rebased

@jenweber
Copy link
Contributor Author

jenweber commented Mar 7, 2019

P.S. Thanks everyone for your careful reviews ❤️

@jenweber jenweber changed the title Rough draft of new Templates intro New Templates intro Mar 7, 2019
@jenweber jenweber dismissed locks’s stale review March 7, 2019 05:10

All issues addressed, and have been reviewed again

@jenweber jenweber merged commit 66463f2 into master Mar 7, 2019
@jenweber jenweber deleted the templates branch March 7, 2019 06:46
cspanring pushed a commit to cspanring/guides-source that referenced this pull request Apr 12, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants