|
1 | 1 | # Using `pi-slot`
|
2 | 2 |
|
3 |
| -... |
| 3 | +The `pi-slot` component introduces a micro frontend independent rendering slot. It will automatically look into all currently loaded micro frontends - trying to locate exposed components by the given `name` attribute. All found components will be rendered inside the `pi-slot`. |
| 4 | + |
| 5 | +Consider the following HTML: |
| 6 | + |
| 7 | +```html |
| 8 | +<div class="d-flex p-2 justify-content-center"> |
| 9 | + <pi-slot name="counter"></pi-slot> |
| 10 | +</div> |
| 11 | +``` |
| 12 | + |
| 13 | +Inside this area all found components with the name `counter` will be rendered. Let's say we only found one. The resulting HTML would be: |
| 14 | + |
| 15 | +```html |
| 16 | +<div class="d-flex p-2 justify-content-center"> |
| 17 | + <pi-slot name="counter"> |
| 18 | + <pi-component cid="12356"></pi-component> |
| 19 | + </pi-slot> |
| 20 | +</div> |
| 21 | +``` |
| 22 | + |
| 23 | +At this point the `pi-component` would take over; except that it does not need to resolve any micro frontend. As the `cid` attribute is set it can directly render the referenced component. |
| 24 | + |
| 25 | +What if the `pi-slot` found multiple components? Let's say we found three. The resulting HTML could look like this: |
| 26 | + |
| 27 | +```html |
| 28 | +<div class="d-flex p-2 justify-content-center"> |
| 29 | + <pi-slot name="counter"> |
| 30 | + <pi-component cid="12356"></pi-component> |
| 31 | + <pi-component cid="12357"></pi-component> |
| 32 | + <pi-component cid="12358"></pi-component> |
| 33 | + </pi-slot> |
| 34 | +</div> |
| 35 | +``` |
| 36 | + |
| 37 | +Maybe this is exactly what we want - maybe not. If not, we might be interested in actually containing these elements in another structure. |
| 38 | + |
| 39 | +By using a `<template>` element together with the `item-template-id` attribute we can wrap each component in another structure: |
| 40 | + |
| 41 | +```html |
| 42 | +<div class="d-flex p-2 justify-content-center"> |
| 43 | + <pi-slot name="counter" item-template-id="my-template"></pi-slot> |
| 44 | +</div> |
| 45 | +<template id="my-template"> |
| 46 | + <div class="some-class"> |
| 47 | + <slot></slot> |
| 48 | + </div> |
| 49 | +</template> |
| 50 | +``` |
| 51 | + |
| 52 | +The resulting HTML is: |
| 53 | + |
| 54 | +```html |
| 55 | +<div class="d-flex p-2 justify-content-center"> |
| 56 | + <pi-slot name="counter" item-template-id="my-template"> |
| 57 | + <div class="some-class"> |
| 58 | + <pi-component cid="12356"></pi-component> |
| 59 | + </div> |
| 60 | + <div class="some-class"> |
| 61 | + <pi-component cid="12357"></pi-component> |
| 62 | + </div> |
| 63 | + <div class="some-class"> |
| 64 | + <pi-component cid="12358"></pi-component> |
| 65 | + </div> |
| 66 | + </pi-slot> |
| 67 | +</div> |
| 68 | +<template id="my-template"> |
| 69 | + <div class="some-class"> |
| 70 | + <slot></slot> |
| 71 | + </div> |
| 72 | +</template> |
| 73 | +``` |
0 commit comments