Skip to content

Commit ef54d92

Browse files
Kenneth Larsensivakumar-kailasam
authored andcommitted
v3.2.0: Added docs on let helper
1 parent 390e75f commit ef54d92

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

guides/v3.2.0/templates/built-in-helpers.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,32 @@ format of a concatenated string.
3636

3737
This will display the result of `this.get('foo.item1')` when index is 1,
3838
and `this.get('foo.item2')` when index is 2, etc.
39+
40+
### Built-in block helpers
41+
Now let's say your template is starting to get a bit cluttered and you now want to clean up the logic in your templates. This can be achieved with the `let` block helper. The [`{{let}}`](#) helper lets you create new bindings in your template.
42+
43+
Say your template now looks like this:
44+
45+
```handlebars
46+
Welcome back {{concat (capitalize person.firstName) ' ' (capitalize person.lastName)}}
47+
48+
Account Details:
49+
First Name: {{capitalize person.firstName}}
50+
Last Name: {{capitalize person.lastName}}
51+
```
52+
53+
As mentioned in the previous section we use the `concat` helper to render both `person.firstName` and `person.lastName` in one go. But we also want to make sure that the names are capitalized. It gets a bit repetitive to keep writing `capitalize` and honestly, we might just forget it at some point. Thankfully, we can use the `{{let}}` helper to fix this:
54+
55+
```handlebars
56+
{{#let (capitalize person.firstName) (capitalize person.lastName)
57+
as |firstName lastName|
58+
}}
59+
Welcome back {{concat firstName ' ' lastName}}
60+
61+
Account Details:
62+
First Name: {{firstName}}
63+
Last Name: {{lastName}}
64+
{{/let}}
65+
```
66+
67+
Now, as long as your template is wrapped in the `let` helper you can access the capitalized first name and last name as `firstName` and `lastName` instead of `(capitalize person.firstName)`.

0 commit comments

Comments
 (0)