hasBlockpublic
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
Please login to continue.