Thursday, October 21, 2010

How to Create HTML5 Website and Page Templates for Visual Studio 2010

Now that I work at Microsoft, I’m using Visual Studio 2010 as my main editor. By default, an empty web page is created with an XHTML 1.0 doctype and it’s pretty barebones. Since I’m focusing on HTML5 & JavaScript development, having to constantly update the page with references to the new HTML5 doctype, jQuery, Modernizr and all of the other tags I use for my pages was becoming a drag.
Today, I noticed a blog post by Zander Martineau in which he added a lot of HTML5 goodness to the Coda IDE in the form of clips, which is the code snippet format supported by Coda. This got me inspired to find out how to do something similar in Visual Studio, so I pinged Damian Edwards of the Visual Studio team for advice. He pointed me to the following article which explained how to create “Item Templates” in Visual Stuido.
The gist of it is that you can take any page that you create and turn it into a re-usable template via the “File->Export Template…” wizard. It walks you through the process of choosing a specific file or entire project/website to use as a template.
Adding a Page Template
So here’s the basic HTML5 template I wanted to include:
<!doctype html>
<html lang="en">
<head>
   <meta charset="utf-8" />
   <title></title>
   <meta name="description" content="" />
   <meta name="keywords" content="" />
   <meta name="author" content="" />
   <meta name="viewport" content="width=device-width; initial-scale=1.0" />
   <!-- !CSS -->
   <link href="css/html5reset.css" rel="stylesheet" />
   <link href="css/style.css" rel="stylesheet" />
   <!-- !Modernizr - All other JS at bottom
   <script src="js/modernizr-1.5.min.js"></script> -->
   <!-- Grab Microsoft's or Google's CDN'd jQuery. fall back to local if necessary -->
   <!-- <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script> -->
   <!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script> -->
   <script>      !window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script>
</head>
<body>
   <div id="container">
   </div>
</body>
</html>
Read more: REY BANGO