marko

Use component/tag contents in Marko template


Say I'd like to have a component that wraps its contents (aka children):

<article>
  <header>${input.heading}</header>
  <section> ... contents come here ... </section>
<article>

Then use it like:

...
<my-article heading='Test'>
  Lorem ipsum <s>dolor</s> sit amet
</my-article>

How do I access the contents in the template?


Solution

  • Or a simple solution:

    <article>
      <header>${input.heading}</header>
      <section><include(input) /></section>
    <article>
    

    And use:

       <my-article heading='Test'>
          Lorem ipsum <s>dolor</s> sit amet
       </my-article>