Alex Roth
Alex Roth

Reputation: 162

Getting the block content from component view

I'm designing a component to help with alert messages within our application. Right now, it's designed to display either content passed in from an attribute, the block content within, or both. As an example:

{{#cos-alert message="This is the first line" displayBlock="all"}}
    This is the second line
{{/cos-alert}}

would render:

This is the first line
This is the second line

My example handlebars template:

{{message}}<br/>
{{yield}}

However, sometimes the message attribute is bound to a property from the view that would cause it to be empty. We want to detect if there is block content, and if so we want to display it. If not, we want to hide the component with the isVisible property until there is content to display.

I haven't been able to find a way to detect whether or not there is block content, however. I could be missing something but after searching for a while I've found nothing. Is it possible to get the value of yield from the component view?

Upvotes: 0

Views: 71

Answers (1)

Lux
Lux

Reputation: 18240

To check of there is a message check the message property. To check if there is a template check the template property.

Look here.

That is probably what u need to check if there is a template:

 hasTemplate: Em.computed.bool('template')

Upvotes: 1

Related Questions