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

add couple of remarks regarding inline/block usage of -if- #1770

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions guides/release/components/conditional-content.md
Original file line number Diff line number Diff line change
@@ -114,6 +114,17 @@ Like many programming languages, Ember also allows you to write `if else` and
{{/if}}
```

The block form of the `if` statement is typically used to wrap
HTML elements or another block. If you want to use `if` inside of an HTML element, keep reading to learn about how to use inline `if` instead.

Here's an example of a block `if`, wrapping some HTML elements:

```handlebars {data-filename="app/components/sign-in.hbs"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most common way to conditionally render an attribute would be like this:

<button disabled={{@disabled}} class="btn">Sign In</button>

Personally, I would use a different example.

{{#if @disabled}}
<button disabled class="btn">Sign In</button>
{{else}}
<button class="btn">Sign In</button>
{{/if}}

## Inline `if`

@@ -225,6 +236,14 @@ It looks similar to a ternary operator.
{{if condition value1 value2}}
```

Similarly to block `if`, you need to pay attention where inline `if` is placed.
Inline `if` can be used only inside attribute values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline if can be used only inside attribute values of HTML elements.

That's not true.
Literally the example above shows valid usage that's unrelated to HTML attributes.
These are valid examples as well:

Conditional argument value:

<Foo @foo={{if this.bar "bar" "baz"}} />

Applying a modifier conditionally:

<button type="button" {{(if @onClick (modifier this.on "click" @onClick))}} />

of HTML elements. For example:

```handlebars {data-filename="app/components/spinner.hbs"}
<span class="spinner {{if @inProgress 'visible' 'invisible'}}">
</span>


## Learn More