如何创建&"MasterPage&"在HTML中 [英] How to create a "MasterPage" in HTML

查看:46
本文介绍了如何创建&"MasterPage&"在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.

任何有用的帮助将不胜感激.

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.

iframes 而言,我强烈建议您不要使用单独的 iframes 来构建网站.这将变得无法控制和维护.由于您可能无法控制iframe内容.另外,如果页面上需要所有HTML,则应为页面重新创建HTML,而不是使用 iframes 填充.

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.

因此,请使用框架.不要写一些疯狂的方法来替换页面上的内容.框架一经维护便很容易,并且在以后使用时也很有意义.

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

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