widgetを表示する Meteor アプリケーションがあるとします。ウィジェットは、次のいくつかの形式のいずれかを持つことができます。
<template name="textWidget">
<h1>{{myTitle}}</h1>
<p>{{myTextContent}}</p>
</template>
<template name="imgWidget">
<h1>{{myTitle}}</h1>
<img src="{{myImagePath}}" />
</template>
<template name="listWidget">
<h1>{{myTitle}}</h1>
<ul>
{{#each items}}
{{> listWidgetItem}}
{{/each}}
</ul>
</template>
特定のレコード タイプを指定して特定のテンプレートをレンダリングするための適切なパターンはありますか?
素朴に、私は次のようなことができます:
<template name="masterTemplate">
{{#each widgets}}
{{#if widgetType "text"}}
{{> textWidget}}
{{else}}
{{#if widgetType "img"}}
{{> imgWidget}}
{{else}}
{{if ... }} ... {{/if}}
{{/if}}
{{#/if}}
{{/each}}
</template>
次のようなヘルパーを使用します。
Template.masterTemplate.widgetType = function(cmp) {
return cmp === this.data.type;
};
ただし、これは非常に扱いにくく、柔軟性に欠ける方法のように思えます。このユース ケースの明らかなライブラリまたはデザイン パターンが不足していますか?