Component#hasBlock

hasBlockpublic

Defined in packages/ember-htmlbars/lib/component.js:198
Available since 1.13.0

Returns true when the component was invoked with a block template.

Example (hasBlock will be false):

{{! templates/application.hbs }}

{{foo-bar}}

{{! templates/components/foo-bar.hbs }}
{{#if hasBlock}}
  This will not be printed, because no block was provided
{{/if}}

Example (hasBlock will be true):

{{! templates/application.hbs }}

{{#foo-bar}}
  Hi!
{{/foo-bar}}

{{! templates/components/foo-bar.hbs }}
{{#if hasBlock}}
  This will be printed because a block was provided
  {{yield}}
{{/if}}

This helper accepts an argument with the name of the block we want to check the presence of. This is useful for checking for the presence of the optional inverse block in components.

{{! templates/application.hbs }}

{{#foo-bar}}
  Hi!
{{else}}
  What's up?
{{/foo-bar}}

{{! templates/components/foo-bar.hbs }}
{{yield}}
{{#if (hasBlock "inverse")}}
  {{yield to="inverse"}}
{{else}}
  How are you?
{{/if}}

Returns:

Boolean
doc_EmberJs
2016-11-30 16:48:48
Comments
Leave a Comment

Please login to continue.