【问题标题】:Jade precompile input attributes with handlebars conditions带有把手条件的 Jade 预编译输入属性
【发布时间】:2013-06-19 23:58:22
【问题描述】:

短版:我希望 Jade 生成类似 {{#if readOnly}}readonly{{/if}} 属性的东西。 这可能吗?

我将我的 Jade 模板预编译为客户端把手 .hbs 模板文件,以便让 Jade 语法类似于

input(type="text", name="dlg_{{fieldName}}",id="dlg_{{fieldName}}")

成为预编译

<input type="text" name="dlg_{{fieldName}}" id="dlg_{{fieldName}}" />

我想包含一个客户端条件“只读”属性,但这种解决方案不起作用

input(type="text",readonly="{{#if readOnly}}true{{else}}false{{/if}}",name="dlg_{{fieldName}}",id="dlg_{{fieldName}}")

我需要在预编译时生成(没有玉条件)是

<input type="text" {{#if readOnly}}readonly{{/if}} name="dlg_{{fieldName}}" id="dlg_{{fieldName}}" />

我知道我可以在翡翠模板中直接包含html代码,但这完全失去了翡翠的趣味和美感。

这样的解决方案也可以,但不是最佳的

|{{#if readOnly}}
input(type="text", name="dlg_{{fieldName}}",id="dlg_{{fieldName}}",readonly)
|{{else}}
input(type="text", name="dlg_{{fieldName}}",id="dlg_{{fieldName}}")
|{{/if}}

我还想包含一个像“data-readony={{#if readOnly}}true{{else}}false{{/if}}”这样的属性并在客户端设置只读,但这需要在之后进行更多处理模板已渲染。

【问题讨论】:

    标签: handlebars.js pug mustache


    【解决方案1】:

    简单地回答,我认为你不能。 我宁愿推荐使用玉客户端:

    if readOnly
      input(type="text", name="dlg_#{fieldName}", id="dlg_#{fieldName}", readonly)
    

    只需将{client: true} 传递给jade。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多