Skip to content

Commit

Permalink
Add docs about inline templates interpolation (#1874)
Browse files Browse the repository at this point in the history
* Add docs about inline templates interpolation

* Changelog
  • Loading branch information
Spone authored Oct 18, 2023
1 parent 2427ce7 commit 6ed8d7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ nav_order: 5

*Alexandre Ignjatovic*

* Improve docs about inline templates interpolation

*Hans Lemuet*

## 3.6.0

* Refer to `helpers` in `NameError` message in development and test environments.
Expand Down
22 changes: 22 additions & 0 deletions docs/guide/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ class InlineErbComponent < ViewComponent::Base
end
```

### Interpolations

When using Slim, interpolations have to be escaped, or they'll be evaluated in the context of the ViewComponent class.

```ruby
class InlineSlimComponent < ViewComponent::Base
slim_template <<~SLIM
p Hello, #{name}!
p Hello, \#{name}!
SLIM

def name
"World"
end
end
```

will render:

<p>Hello InlineSlimComponent!</p>
<p>Hello World!</p>

## Sibling file

Place template file next to the component:
Expand Down

0 comments on commit 6ed8d7f

Please sign in to comment.