把手,避免编译(忽略)模板的一部分? [英] Handlebars, avoid compiling (ignore) part of a template?

查看:94
本文介绍了把手,避免编译(忽略)模板的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉Handlebar编译器忽略模板块.

我知道有\解决方案,例如:

\{{ is.ignored}}

但是有什么可以做的,但是对于一个完整的块,例如:

<script type="text/x-handlebars-template" id="my-template">
    <ul>
        {{#each items}}
            <li><a href="{{url}}" title="{{title}}">{{display}}</a></li>
        {{/each}}
    </ul>
</script>

我相信最好是(并且更具可读性)使用类似{{#ignore}}{{/ignore}}的东西,而不是在各处都添加\.

我试图使用块帮助器找到一些东西,要么自己创建东西,但我无法接触到块内部的非编译版本.

解决方案

不幸的是,西里尔的答案似乎已经过时了?我在有关原始块的把手文档中找到了这种替代方法:

原始块

原始块可用于需要处理未处理的胡子块的模板.

{{{{raw-helper}}}}
    {{bar}}
{{{{/raw-helper}}}}

将执行帮助程序的原始帮助程序,而无需解释其内容.

Handlebars.registerHelper('raw-helper', function(options) {
    return options.fn();
});

将呈现

{{bar}}

Is there a way to tell the Handlebar compiler to ignore a block of template.

I know there is the \ solution, like :

\{{ is.ignored}}

but is there something that would do the same, but for a complete block, like :

<script type="text/x-handlebars-template" id="my-template">
    <ul>
        {{#each items}}
            <li><a href="{{url}}" title="{{title}}">{{display}}</a></li>
        {{/each}}
    </ul>
</script>

I believe it would be better (and far more readable) to have something like {{#ignore}}{{/ignore}} instead of adding \ everywhere.

I tried to find something using block helpers, either building something myself, but I can't get my hand on the non-compiled version of what's inside the block.

解决方案

Unfortunately, Cyril's answer seems out of date? I found this alternative in the Handlebars documentation on raw blocks:

Raw Blocks

Raw blocks are available for templates needing to handle unprocessed mustache blocks.

{{{{raw-helper}}}}
    {{bar}}
{{{{/raw-helper}}}}

will execute the helper raw-helper without interpreting the content.

Handlebars.registerHelper('raw-helper', function(options) {
    return options.fn();
});

will render

{{bar}}

这篇关于把手,避免编译(忽略)模板的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆