Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created September 3, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbnv/ce18a6600c6f7547cfd9 to your computer and use it in GitHub Desktop.
Save jbnv/ce18a6600c6f7547cfd9 to your computer and use it in GitHub Desktop.
An example of view composition in Durandal. From Durandal's HTML Samples download.
<div>
<h2>Child View One</h2>
<span data-bind="text: $root.propertyOne"></span>
</div>
<div>
<h2>Child View Two</h2>
<span data-bind="text: propertyTwo"></span>
<div data-part="content">Some default content goes here.</div>
</div>
<section>
<h1>The Views Below Are Composed In Different Ways</h1>
<!--ko compose: 'childView1.html'--><!--/ko-->
<!--ko compose: 'childView2.html'--><!--/ko-->
<!--ko compose: { model:'viewComposition/inlineModule', mode:'inline'}-->
<h3 data-bind="text: someProperty"></h3>
<!--/ko-->
<!--ko compose: { view:'childView2.html', mode:'templated' }-->
<div data-part="content">This is a view part override of the default content....</div>
<!--/ko-->
</section>
define(function() {
return {
propertyOne: 'This is a databound property from the root context.',
propertyTwo: 'This property demonstrates that binding contexts flow through composed views.'
};
});
define(function(){
return {
someProperty:'This is being bound against an inline view.'
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment