Ember.js Ember.Templates.helpers has-block-params() Method
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 has-block-params() method is used to indicate if the component is invoked with params.
Syntax:
has-block-params(the)
Parameters:
- the: It is the name of the block which is invoked.
Return: Boolean ‘true’ if the component was invoked with block params.
Steps to Install and Run Ember.js:
Step 1: To run the following examples, you need to have an ember project. 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 has1
app/components/compact2.hbs
HTML
{{#if (has-block-params)}} < h2 > Welcome {{yield this.favoriteFlavor}}, This Component with Params. </ h2 > {{else}} < h2 > Welcome {{yield}}, This Component without Params. </ h2 > {{/if}} |
app/templates/has1.hbs
HTML
< Compact2 as |favoriteFlavor|> Sam </ Compact2 > < Compact2 > Beginner </ Compact2 > |
Output:
Example 2: Type the following code to generate the route for this example:
ember generate route has2
app/components/compact.js
HTML
{{#if (has-block-params)}} < h2 > This Component is invoke with params. </ h2 > {{else}} < h2 > {{yield}} This block of component invoke without params. </ h2 > {{/if}} |
app/templates/has2.hbs
HTML
< Compact as |params|> Hi Beginner </ Compact > < Compact > Hi coders </ Compact > {{outlet}} |
Output:
Reference: https://api.emberjs.com/ember/4.4/classes/Ember.Templates.helpers/methods/action?anchor=has-block-params
Contact Us