简体   繁体   English

如何将html元素列表作为参数传递给Closure模板

[英]How can I pass a list of html element as parameter into a Closure template

My template is this one below, and I'd like to use a list of html as parameter 我的模板是下面的模板,我想使用HTML列表作为参数

{template .myTemplate}
    {@param title: string}
    {@param? listHtml: list<html>}
     <ul>
     {foreach $item in $listHtml}
       <li>
         <a>{$item}</a>
       </li>
     {/foreach}
    </ul>
{/template}

My problem is that I don't know how to pass a list of html elements as parameter when I call the template. 我的问题是,我在调用模板时不知道如何将html元素列表作为参数传递。

{call desktop.common.myTemplate }
     {param title: 'Contact us' /}
     {param listHtml kind="html" }
                          ????  
     {/param}
{/call}

How about breaking out a helper template: 如何分解一个辅助模板:

{template .myTemplate}
  {@param title: string}
  {@param? items: html}
  <ul>
    {$items}
  </ul>
{/template}

{template .myItemTemplate}
  {@param content: html}
  <li>
    <a>{$content}</a>
  </li>
{/template}

Which pushes iteration to the caller, where I assume the list of items is static: 这将迭代推送到调用者,在此我假设项目列表是静态的:

{call desktop.common.myTemplate }
  {param title: 'Contact us' /}
  {param items kind="html"}
    {call desktop.common.myItemTemplate}
      {param content kind="html"}foo{/param}
    {/call}
    {call desktop.common.myItemTemplate}
      {param content kind="html"}bar{/param}
    {/call}
  {/param}
{/call}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM