私の理解によると、3つのセクション(任意の数)が必要だとしましょう。ヘッダー、コンテンツ、フッター、次のようにできます
<script type="text/x-handlebars" data-template-name="application">
{{view MyApp.HeaderView}}
{{#view MyApp.ContentView}}
{{outlet}}
{{/view}}
{{view MyApp.FooterView}}
</script>
<script type="text/x-handlebars" data-template-name="app-header">
All your Header related HTML
</script>
<script type="text/x-handlebars" data-template-name="app-content">
HTML related to content
{{yield}} //this will be explained at the end
More HTML if you want
</script>
<script type="text/x-handlebars" data-template-name="app-footer">
HTML related to footer
</script>
MyApp.HeaderView = Ember.View.extend({
templateName: 'app-header'
})
MyApp.ContentView = Ember.View.extend({
templateName: 'app-content'
})
MyApp.FooterView = Ember.View.extend({
templateName: 'app-footer'
})
MyApp.ApplicationView = Ember.View.extend({
templateName: 'application'
})
簡単に説明する{{yield}}
と、特定のビューのブロック ヘルパーの間にあるものはすべてそこに入ります。上記の の例ではMyApp.ContentView
、ハンドルバーで{{outlet}}
定義された{{#view MyApp.ContentView}}
が に挿入されます。同様の行で、 layoutNameプロパティとtemplateName{{yield}}
の違いを示します。財産、
App.someView = Ember.View.extend({
tagName: 'a',
templateName: 'a-template',
layoutName: 'a-container'
})
<script type="text/x-handlebars" data-template-name="a-template">
Hi There
</script>
<script type="text/x-handlebars" data-template-name="a-container">
<span class="container">
{{yield}}
</span>
</script>
次のHTMLになります
<a class="ember-view" id="ember235">
<span class="container ember-view" id="ember234">
Hi There
</span>
</a>
これらの概念を使用して、アプリケーションのハンドルバーを次のように分割します。
{{view App.NavigationView}}
{{outlet}}
最新の残り火ごとに更新
新しい ember はpartials
Rails と同様にサポートします。これで、上記を{{partial}}
次のように変更して使用できます。
{{partial "header"}}
{{outlet}}
{{partial "footer"}}
Ember は、このテンプレートに遭遇すると、名前が_header (レールに似ています)のテンプレートを探し、テンプレートを挿入します (フッターも同様です)。
コントローラーを関連付けたい場合は、{{render}}
ヘルパーを使用できます
{{render "sidebar"}}
sidebarという名前のテンプレートをハンドルバーの指定された場所に挿入し、App.SidebarController
それに関連付けます。
注:{{render 'sidebar'}}
同じハンドルバー ファイルで複数回使用することはできません。
ただし、特定のページで複数の場所を表示するなどのウィジェットを使用する場合は、{{view}}
ヘルパーを使用します