【问题标题】:Use component/tag contents in Marko template在 Marko 模板中使用组件/标签内容
【发布时间】:2017-12-21 06:12:06
【问题描述】:

假设我想要一个包装其内容的组件(也称为子组件):

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

然后像这样使用它:

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

如何访问模板中的内容?

【问题讨论】:

    标签: marko


    【解决方案1】:

    或者一个简单的解决方案:

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

    并使用:

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

    【讨论】:

      【解决方案2】:

      找到解决方案 - &lt;include&gt; 可重用/嵌套内容:

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

      然后像这样使用它:

      <my-article heading='Hello'>
        <@body>Lorem ipsum dolor sit <u>amet</u></@body>
      </my-article>
      

      【讨论】:

      • 或者使用&lt;include(input) /&gt;标签
      猜你喜欢
      • 2019-12-24
      • 2019-12-31
      • 2017-10-11
      • 1970-01-01
      • 2014-03-20
      • 2015-08-07
      • 1970-01-01
      • 2018-11-19
      • 2013-06-05
      相关资源
      最近更新 更多