Ember.js is an open-source JavaScript framework used for developing large client-side web applications which are 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() method is used to check if the component is invoked with a block or not.
Syntax:
has-block(the)
Parameters:
- the: It is the name block.
Return Value: Boolean ‘true’ if the component was invoked with a block.
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 server
Example 1: Type the following code to generate the route for this example:
ember generate route has1
app/components/compact2.hbs
< h1 >
Following block in invoke with component< br />
{{yield}}
</ h1 >
|
app/templates/has1.hbs
< Compact2 >
This Block is is invoke with component.
</ Compact2 >
{{outlet}} |
Output:
Example 2: Type the following code to generate the route for this example:
ember generate route has2
app/components/compact.hbs
{{#if (has-block)}} < h2 >
{{yield}}
</ h2 >
{{else}} < h2 >
This comment is from block less component invoke.
</ h2 >
{{/if}} |
app/templates/has.hbs
< Compact >
This Block is is invoke with component.
</ Compact >
{{outlet}} |
Output:
Reference: https://api.emberjs.com/ember/4.4/classes/Ember.Templates.helpers/methods/has-block?anchor=has-block