热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

[转]HowtoCreateHTML5WebsiteandPageTemplatesforVisualStudio2010

本文转自:http:blog.reybango.com20100921how-to-create-html5-website-and-page-templates-for-visual-studio-2010 NowthatIworkatMicrosoft,I’musingVisualStudio2010asmymainedit

本文转自:http://blog.reybango.com/2010/09/21/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:

<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=" />
  
    
    <link href="css/html5reset.css" rel="stylesheet" />
    <link href="css/style.css" rel="stylesheet" />
  
    
  
    
    
    
    <script>      !window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')script>
  
head>
  
<body>
    <div id="container">
  
    div>
body>
  
html>

After I created and saved this page, I went to “File->Export Template…” and followed these steps:

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

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

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

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

Now, when I select “File->New File…” to add a new item, my template is available:

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

Adding a Web Site Template

Creating this page template was a huge help. I can now start with a fresh template that specifically works for my style of development but I didn’t want to stop there. I also wanted to create a skeleton that I could use as the basis for new websites and I wanted it to package all of the important files that I use from the get-go. In this case, I wanted:

  • My HTML5 basic page template
  • jQuery
  • Modernizr
  • HTML5 Reset CSS file
  • An empty CSS file called style.css
  • A consistent folder structure for all of these

The first thing I needed to do was to create a new website in Visual Studio. From there, I needed to create and/or organize all of the files that I wanted as the basis for my skeleton. Using the same Export Template wizard, I followed the following steps to create my project skeleton:

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

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

So now when I select “File=>New Web Site” I see my new template:

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

and when I choose that, here’s what gets loaded for my new site:

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

Download the Templates

Note: The templates in this article have been updated to support jQuery 1.5.1 & Modernizr 1.7. Check it out here.

This is a huge time-saver for me and I want to share this. I’ve made both templates available for download so you can drop them into Visual Studio yourself. Just grab the specific file and drop the zip into the folder I specified:

HTML5 Page Template

Drop this into “Visual Studio 2010 > Templates > ItemTemplates” folder

HTML5 Web Site Template

Drop this into “Visual Studio 2010 > Templates > ProjectTemplates” folder

Related posts:

  1. jQuery Javascript Templates Tutorial: Nesting Templates In my last post, I presented an intro to how...
  2. Not Using jQuery Javascript Templates? You’re Really Missing Out. In preparation for my upcoming talk on jQuery Templates, I’ve...
  3. jQuery Javascript Templates Tutorial: Inline Expressions and Code Blocks So far in my series on jQuery Javascript Templating, I’ve...
  4. How to Easily Inject jQuery into any Web Page I use jQuery…a lot. It just makes Javascript development much...
  5. I’m Presenting on jQuery Templates at ThinkVitamin’s jQuery Online Conference This coming Monday (7/12/2010), I’ll be one of the speakers...

 


推荐阅读
author-avatar
咿呀最有味先
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有