Code Reuse with External Templates and Knockout.js: Listing 1.

The product-details template contained within a script tag.

<script id="productDetails" type="text/html">
<div data-bind="with: selectedProduct">
  <div class="photoContainer leftFloat">
    <img src="/images/guitar.jpg" 
      data-bind="attr: {alt: shortDesc}" 
      class="photoThumbnail"></img>
  </div>
  <div>
    <span>Brand: </span>
    <span data-bind="text: model().brand" 
      class="textValues"></span>
  </div>
  <div>
    <span>Model: </span>
    <span data-bind="text: model().name" 
      class="textValues"></span>
  </div>
  <div>
    <span>Price: </span>
    <span data-bind=
      "text: my.formatCurrency(salePrice())" 
      class="textValues"></span>
  </div>
  <div>
    <span>Description:</span></div>
  <div>
    <span data-bind="text: description" 
      class="textValues"></span>
  </div>
</div>
</script>

About the Author

John Papa is a Microsoft Regional Director and former Microsoft technical evangelist. Author of 100-plus articles and 10 books, he specializes in professional application development with Windows, HTML5, JavaScript, CSS, Silverlight, Windows Presentation Foundation, C#, .NET and SQL Server. Check out his online training with Pluralsight; find him at johnpapa.net and on Twitter at twitter.com/john_papa.

comments powered by Disqus

Featured

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

  • TypeScript Tops New JetBrains 'Language Promise Index'

    In its latest annual developer ecosystem report, JetBrains introduced a new "Language Promise Index" topped by Microsoft's TypeScript programming language.

Subscribe on YouTube