litteral ${} and {{ }} in jquery templates

584 Views Asked by At

Using JQuery templates, what is the best way to output literal ${} and {{ }} strings? I need this because I would like to write templates that themselves generate other templates.

2

There are 2 best solutions below

0
On BEST ANSWER

I am not sure of your exact needs, but if you are, for whatever reason, not able to use nested templates, then how about as a workaround either something like:

<script id="options" type="text/html">
        $&#123;test&#125;
</script>

or

<script id="options" type="text/html">
        ${writeVariable('test')}
</script>

with writeVariable (and other helpers or a more generic/advanced version of this one) defined elsewhere:

function writeVariable(varName) {
    return "${" + varName + "}";   
}

I did see reference in another post to a {#literal} tag, but I don't see that available anywhere in recent jquery.tmpl.js code.

1
On

I don't think you want to write ${} and {{}} as literals. I think you want to use nested templates: http://api.jquery.com/template-tag-tmpl/