Dustin
Dustin

Reputation: 4185

Aurelia Custom Elements & Content

I was reading through this tutorial and I want to do something similar, but instead of using attributes of my custom elements, I'll like to access the content inside of my custom element tags. I can't seem to figure this out. So instead of html looking like this:

<modal>  
  <modal-header title="Edit Person"></modal-header>
  <modal-body content="person-information"></modal-body>
  <modal-footer buttons.bind="['Cancel']"></modal-footer>
</modal>  

I want it to look more like this:

<modal>  
  <modal-header>Edit Person</modal-header>
  <modal-body>
      <form>...</form>
  </modal-body>
  <modal-footer buttons.bind="['Cancel']"></modal-footer>
</modal>  

Is this possible?

Upvotes: 4

Views: 1370

Answers (1)

PW Kad
PW Kad

Reputation: 14995

Yes that can be accomplished with Content Selectors -

modal-header.html

<template>
  <slot></slot>
</template>

You can be more specific as well by specifying what content to match using any standard CSS selector -

<template>
  <slot="form"></slot>
  <slot select=".form-element"></slot>
</template>

Aurelia documentation

Upvotes: 5

Related Questions