将变量传递到Meteor中的模板包含空格键和常规空格键?

时间:2015-06-11 15:36:49

标签: meteor spacebars

我的模板中有很多类似的块。

每个块之间唯一真正的区别是sku(例如hdrPhotos, panos, twilightPhotos, exteriors)。

我更愿意编写一个带有sku参数的模板并循环遍历skus数组来创建每个块,但是如何将值插入已经使用空格键{{}}的内容中?

{{> afFieldInput name="servicesSelected.hdrPhotos.selected" type="boolean-checkbox" noselect="true"}}

{{formatToCurrency currentPrice.hdrPhotos}}

{{{services "hdrPhotos" "html"}}}

    <div class="col-md-12">
        {{> afFieldInput name="servicesSelected.hdrPhotos.selected" type="boolean-checkbox" noselect="true"}}
      <div class="divider small-margins">
      </div>
      <div class="item-description">
        <p><b>{{formatToCurrency currentPrice.hdrPhotos}}</b> - {{services "hdrPhotos" "description"}}</p>
        <p>{{{services "hdrPhotos" "html"}}}</p>
      </div>
    </div>

    <div class="col-md-12">
        {{> afFieldInput name="servicesSelected.panos.selected" type="boolean-checkbox" noselect="true"}}
      <div class="divider small-margins">
      </div>   
      <div class="item-description">
        <p><b>{{formatToCurrency currentPrice.panos}}</b> - {{services "panos" "description"}}</p>
        <p>{{{services "panos" "html"}}}</p>
      </div>
    </div>

    <div class="col-md-12">
        {{> afFieldInput name="servicesSelected.twilightPhotos.selected" type="boolean-checkbox" noselect="true"}}
      <div class="divider small-margins">
      </div>
      <div class="item-description">
        <p><b>{{formatToCurrency currentPrice.twilightPhotos}}</b> - {{services "twilightPhotos" "description"}}</p>
        <p>{{{services "twilightPhotos" "html"}}}</p>
      </div>
    </div>

    <div class="col-md-12">
        {{> afFieldInput name="servicesSelected.exteriors.selected" type="boolean-checkbox" noselect="true"}}
      <div class="divider small-margins">
      </div>
      <div class="item-description">
        <p><b>{{formatToCurrency currentPrice.exteriors}}</b> - {{services "exteriors" "description"}}</p>
        <p>{{{services "exteriors" "html"}}}</p>
      </div>
    </div>

我无法使用字符串连接:

itemBlock: function(sku){
    var string = ''  +
    '<div class="col-md-12">' +
      '{{> afFieldInput class="track-order-change label-to-bold-if-checked" name="servicesSelected.hdrPhotos.selected" type="boolean-checkbox" noselect="true"}}' +
    '<div class="divider small-margins">' +
    '</div>' +
    '<div class="item-description">' +
    '<p><b>{{formatToCurrency currentPrice.' + sku + '}}</b> - {{services "' + sku + '" "description"}}</p>' +
    '<p>{{{services "' + sku + '" "html"}}}</p>' +
    '</div>' +
'</div>';

return string;
}

在我的html模板中:

{{{itemBlock hdrPhotos}}}

它的HTML部分很好,但{{}}和{{{}}}内的所有内容都以字面形式呈现在页面上(参见屏幕截图)

enter image description here

1 个答案:

答案 0 :(得分:0)

您应该在专用模板中尝试使用nested sub-expressions

{{ > yourSkuTemplate "youSkuType"}}

<template name="yourSkuTemplate ">
    <div class="col-md-12">
        {{> afFieldInput name=(skuServicesSelected) type="boolean-checkbox" noselect="true"}}
      <div class="divider small-margins">
      </div>
      <div class="item-description">
        <p><b>{{formatToCurrency (skuCurrentPrice)}}</b> - {{services (skuName) (skuyDescription}}</p>
        <p>{{{services (skuName) (whatever)}}}</p>
      </div>
    </div>
</template>

其中skuServicesSelected skuName和括号中的所有其他人都是其他帮助者