小胡子里面的小胡子
问题描述:
我有这样的JSON:
{ "something": "http://something.com" }
和这样的HTML:
<a href="{{something}}">{{something}}</a>
当我申请Mustache时,我得到
When I apply Mustache, I get
<a href="%7B%7Bsomething%7D%7D">http://something.com</a>
但我想要的是
<a href="http://something.com">http://something.com</a>
我已经尝试过 {{{something}}}
, {{& }}
,单引号,双引号......我甚至阅读文档。
I already tried {{{ something}}}
, {{& something}}
, single quotes, double quotes... I even read documentation.
你能帮助我吗?
答
确保您的模板源是直文 - 不要尝试将解析后的HTML源作为模板。浏览器会在你的链接href中urlencode / escape这些字符,并导致你看到的%7Bs
和%7Ds
你的代码。小胡子不会认识到这一点。
Make sure your template source is straight text - don't try and grab parsed HTML source as your template. Browsers will urlencode/escape those characters in your link href, and result in those %7Bs
and %7Ds
you see in your code. Mustache won't recognize that.
我认为你传递给小胡子的来源可能无效。
I suppose unescaping the source you pass to mustache might work, though.
Mustache.render(unescape(source),view)