duanmao1319 2014-05-27 14:30
浏览 18
已采纳

与标签的小胡子模板

If I have the following array

array (
    'people' => array(
        [0] => array('name'=>'name1'),
        [1] => array('name'=>'name2', 'last' => true)
    )
);

and I want to output it using a Mustache template so that the final html looks like this:

<div>
    Names: name1, name2
</div>

Though if the array is empty then it shouldn't output anything.

This is my current template

<div>
    {{#people}}
        Names: {{name}}{{^last}}, {{/last}}
    {{/people}}
</div>

which outputs

<div>
    Names: name1, Names: name2
</div>

I understand why it doesn't output what I want but I don't know how to solve it.

  • 写回答

1条回答 默认 最新

  • dtz55359 2014-05-27 14:53
    关注
    <div>
        {{#people.0}}
            Names:
            {{#people}}
                {{name}}{{^last}}, {{/last}}
            {{/people}}
        {{/people.0}}
    </div>
    

    The reason you were getting Names: written twice was because everything inside {{#people}} and {{\people}} is treated as a loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 VBA-JSON中文乱码报错
  • ¥50 dac adc的检定规程
  • ¥20 MIT控制器能控制不稳定系统吗
  • ¥15 公司代码X对业务伙伴X无效,处理方法?
  • ¥15 微信内链接跳转到浏览器打开怎么实现
  • ¥15 三角波可以直接加施密特电路整形到矩形波吗实物
  • ¥15 html,php,在使用html请求php文件时发生了错误,无法请求到php文件读取数据库并用javascript进行数据显示,刷新
  • ¥15 touchsocket udp组播
  • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
  • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错