如何创建和QUOT;母版"在HTML [英] How to create a "MasterPage" in HTML

查看:110
本文介绍了如何创建和QUOT;母版"在HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,我可以创建一个网页,在网站其他页面可以使用HTML?喜欢的东西是什么在母版 ASP.NET 一样。

Is there a way I can create a page that other pages in a website can use in HTML? Something like what the masterpage in ASP.NET does.

任何有益的帮助将是AP preciated。

Any useful help will be appreciated.

推荐答案

HTML本身是一个静态的语言。其他框架建立动态HTML(DHTML),如ASP.NET。

HTML itself is a static language. Other frameworks create dynamic HTML (DHTML) such as ASP.NET.

因此​​,一个纯粹的实现HTML中的母版是不可能的。

So a pure implementation of a "masterpage" in HTML is not possible.

您可以使用JavaScript框架,如AngularJS 的,来帮助你实现HTML中的母版。

You can use a JavaScript framework, such as AngularJS, to help you achieve a "masterpage" in HTML.

如果你有兴趣在.NET中,你仍然可以创建你的HTML母版与一些挂钩到.NET所以它知道如何使主容器。

If you're interested in .NET, you can still create you masterpage in HTML with a few hooks into .NET so it knows how to render the main container.

在ASP.NET MVC的母版(称为ASP.NET MVC的布局),可以有极少数钩回的框架和服务器。 大部分也可以是HTML

In ASP.NET MVC your masterpage (called a layout in ASP.NET MVC) can have very few hooks back into the framework and server. Most of it can be HTML.

<!DOCTYPE html>
<html>
  <head>
    <title>My Movie Site</title>
    <link href="~/Styles/Movies.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div id="container">
        <div id="header">
          <h1>My Movie Site</h1>
        </div>
        <div id="main">
          @RenderBody()
        </div>
        <div id="footer">
          &copy; @DateTime.Now.Year My Movie Site
        </div>
    </div>
  </body>
</html>

另一种选择(如提到的Ondrej)是服务器端包含(SSI)。大多数服务器应该有这个选项。它可以让你注入其他HTML文件插入到页面中,从而允许您没有一个具体的框架,创建一个母版。

Another option (as mentioned by Ondrej) is Server Side Includes (SSI). Most servers should have this option. It will allow you to inject other HTML files into a page, thus allowing you to create a masterpage without a specific framework.

<html>
<title>My Website</title>

<!--#include virtual="/rootPage.html" -->

</html>

在虽然最后,我真的建议使用一个框架,而不是试图链一起一堆的SSI的。

In the end though, I'd really recommend using a framework rather than trying to chain together a bunch of SSIs.

至于内部框架去,我会强烈建议不要使用单独的内部框架来共同建设一个网站。这将成为不可能控制和维护。正如你可能没有在iframe中的内容控制。另外,如果所有的HTML的,需要在页面上,应该为页面重新创建,而不是用酿内部框架

As far as iframes go, I'd highly recommend against using separate iframes to build together a website. That will become impossible to control and maintain. As you may not have control over the iframe content. Also, if all of the HTML is needed on the page, it should be re-created for the page, not stuffed in using iframes.

那么,就用一个框架。不要写一些疯狂的方式来取代你的页面上的内容。一个框架将是易于维护和意义当您返回到它的道路。

这篇关于如何创建和QUOT;母版&QUOT;在HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆