展开variables中的标签
有没有办法让胡须扩大variables内的标签?
我明白这是部分的目的。 但是,正如您在下面的示例中所看到的,由于视图的结构,使用偏分组有时不切实际。
如果不是,我应该如何改变下面的视图的结构? 目前我提前提交每个条目的html
属性。 这似乎并不理想(并打破了改变胡须的分隔符的function)。
例
博客主页的视图:
var view = { title: 'Example blog', entries: [ {url: '/a', html: '<p>The first entry on {{title}}</p>'}, {url: '/b', html: '<p>The second entry on {{title}}</p>'}, {url: '/c', html: '<p>The third entry on {{title}}</p>'} ] };
相应的模板:
{{#entries}} {{{html}}} {{/entries}}
在调用Mustache.render
,我收到了这个。
<p>The first entry on {{title}}</p> <p>The second entry on {{title}}</p> <p>The third entry on {{title}}</p>
我想收到这个:
<p>The first entry on Example blog</p> <p>The second entry on Example blog</p> <p>The third entry on Example blog</p>
小胡子不这样做, 你不希望它 。 它被称为“胡须注入”,它相当于SQL注入。
当Twitter第一次使用Mustache客户端时,发生了一个攻击,其中发送带有Mustache标签的URL会导致任何人查看推文转发。 修复是为了防止胡子双重扩展标签。
尝试这个:
var view = { title: 'Example blog', entries: [ {url: '/a', position: 'first'}, {url: '/b', position: 'second'}, {url: '/c', position: 'third'} ] }; {{#entries}} <p>The {{position}} entry on {{title}} blog</p> {{/entries}}