开发者

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

开发者 https://www.devze.com 2023-02-10 01:11 出处:网络
Using JQuery templates, what is the best way to output literal ${} and {{ }} strings? I need this because I would like to write templates that themselve开发者_高级运维s generate other templates.I am n

Using JQuery templates, what is the best way to output literal ${} and {{ }} strings? I need this because I would like to write templates that themselve开发者_高级运维s generate other templates.


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.


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消