Ember.js Ember.Templates.helpers let() Method
Last Updated :
21 Nov, 2022
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by a large number of websites, including Square, Discourse, Groupon, Linked In, Live Nation, Twitch, and Chipotle.
The let() method is used for receiving one or more positional arguments and yields them as a block to the component.
Syntax:
{{ let arg1 arg2... as |alias1 alias2...|}}
Parameters:
- arg1: It is the first argument that will yield.
- arg2: It is the first argument that will yield.
- alias1: It is the alias name for the first argument.
- alias2: It is the alias name for the second argument.
Steps to Install and Run Ember.js:
Step 1: To run the following examples you will need to have an ember project with you. To create one, you will need to install ember-cli first. Write the below code in the terminal:
npm install ember-cli
Step 2: Now you can create the project by typing in the following piece of code:
ember new <project-name> --lang en
To start the server, type:
ember serve
Example 1: Type the following code to generate the route for this example:
ember generate route let1
app/components/arr.js
Javascript
import Component from '@glimmer/component' ;
import { tracked } from '@glimmer/tracking' ;
import { action } from '@ember/object' ;
export default class Arr2Component extends Component {
@tracked
data = '' ;
@action
m(item, item2) {
let ans = []
for (let i = 0; i < item.length; i++) {
ans.push({ name: item[i], experty: item2[i] })
}
return ans;
}
}
|
app/components/arr.hbs
HTML
< h2 >Name of Employees: </ h2 >
{{#each (this.m @n @e ) as |temp|}}
< li >{{temp.name}} has experties in {{temp.experty}}</ li >
{{/each}}
< br />< br />
|
app/templates/let1.hbs
HTML
{{page-title "let"}}
{{#let (array 'Sam' 'Rahul' 'Dadu' 'Arabh') ( array 'python'
'javascript' 'java' 'PHP') as |name experty| }}
< Arr @n={{name}} @e={{experty}}/>
{{/let}}
|
Output:
Ember.js Ember.Templates.helpers let() Method
Example 2: Type the following code to generate the route for this example:
ember generate route let2
app/components/list.hbs
HTML
{{#if @s}}
{{#each @n as |temp|}}
< li >
{{temp}}
</ li >
{{/each}}
{{/if}}
|
app/templates/let2.hbs
HTML
{{page-title "let"}}
< h2 >
Describing input :
</ h2 >
{{#let (array 'Sam' 'Rahul' 'Dadu' 'Arabh') true as |name show|}}
< List @n={{name}} @s={{show}}/>
< List @n={name}/>
{{/let}}
|
Output:
Ember.js Ember.Templates.helpers let() Method
Reference: https://api.emberjs.com/ember/4.6/classes/Ember.Templates.helpers/methods/let?anchor=let
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...