Mustache inside of href

Evgeny picture Evgeny · Jun 27, 2012 · Viewed 10.7k times · Source

I have JSON like this:

 { "something": "http://something.com" }

and HTML like this:

 <a href="{{something}}">{{something}}</a>

When I apply Mustache, I get

 <a href="%7B%7Bsomething%7D%7D">http://something.com</a>

But what I am trying to get is

 <a href="http://something.com">http://something.com</a>

I already tried {{{ something}}}, {{& something}}, single quotes, double quotes... I even read documentation.

Can you help me?

Answer

Cᴏʀʏ picture Cᴏʀʏ · Jun 27, 2012

I think you need to make use of the & for escaping in combination with surrounding your template with a template script:

<script type="text/template" id="tmpl">
    <a href="{{& something }}">{{ something }}</a>
</script>

Found this example over here.