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

  • Full-Stack with a Side of Copilot: Building and Deploying an App the AI-Accelerated Way

    In this Q&A, developer and VSLive! speaker Esteban Garcia explains how GitHub Copilot can accelerate the full software development lifecycle -- from architecture and code to tests, CI/CD, and Azure deployment -- and how to use it as a repeatable engineering workflow rather than just a faster autocomplete tool.

  • VS Code 1.127 Further Integrates Advanced Browser-AI Tech

    Microsoft's July 1 Visual Studio Code update continues a recent push to make the editor's integrated browser a more capable development surface -- and a more useful tool for AI agents.

  • Support Vector Regression with SGD Training Using C#

    Support vector regression can predict numeric values effectively, and this article shows how to implement and train a kernel SVR model in C# using stochastic sub-gradient descent.

  • New GitHub Switch Limits Repo Issue Creation to Collaborators Only

    After publicly touting pull request limits as a way to cut maintainer noise, GitHub is taking the same idea further with a new setting that lets repository admins restrict issue creation to collaborators only.

Subscribe on YouTube