HTML模板文件 [英] HTML Template File

查看:117
本文介绍了HTML模板文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个初学者的问题,但我一直在网上搜索,所有我可以找到的是我可以下载的免费网站模板。



问题是:
如何在单个文件中编写HTML片段,然后将相同的片段加载到我选择的任何其他HTML文件中?



目的是如果该细分市场发生变化,我只需要更改1个文件,而不是10个/ 100个/ 1000个/ etc。



例如,我可能想要定义一个菜单栏,如下所示:

 < a HREF = ./测试1\" >测试1< / A> < br /> 
< a href =./ Test2> Test2< / a> < br />
< a href =./ Test3> Test3< / a> < br />

然后,我不必在每个单独的文件中重复相同的代码,我可以链接到这个菜单栏。可能是这样的:

 < html> 
<! - 加载菜单栏文件 - >
<! - 将菜单栏放在这里 - >

感谢您访问我的网页。请使用上面的菜单栏进行导航。
< / html>

谢谢。




编辑:虽然听起来可能不重要,但我想制作一些HTML页面来管理我的一些个人文件和数据。作为程序员,我们当然不喜欢重复自己。我最初的想法是,这与链接到CSS文件一样简单,但我现在看到它更复杂,尽管我不确定(从技术角度)为什么它必须是。无论如何,因为我将在我自己的机器上查看这些文件,所以我想我可以安装一些类似PHP的东西来帮助我的努力。

解决方案
div>

您正在描述服务器端包含


服务器端包含对于在整个网站中包含一段常用代码非常有用,例如页眉,页脚和导航菜单。


使用示例:

 <! - #include virtual =../ quote.txt - > 

这会添加 quote.txt 到页面 - 如果您将它添加到多个页面,您可以在这一个文件中进行更改,并将显示在所有页面中。



不同web服务器有不同的支持和附加功能,所以你需要检查你的文档。






许多网站需要动态特性(如从数据库中获取数据)将使用某种服务器端脚本语言来实现这种功能 - 例子包括PHP,Perl,ASP.NET,JSP等等。


I know this is a beginner's question, but I've been searching online and all I can find are "free website templates" that I can download.

The question is: How can I write a segment of HTML in a single file, and then load that exact same segment into any other HTML files that I choose?

The intent is so that if that segment changes, I would only have to change 1 file, rather than 10's/100's/1000's/etc.

For example, I might want to define a menu bar like this:

<a href="./Test1">Test1</a> <br />
<a href="./Test2">Test2</a> <br />
<a href="./Test3">Test3</a> <br />

And then, so I don't have to keep repeating that same code in every single file, I could just link to this menu bar. Maybe something like:

<html>
   <!-- Load "Menu Bar" file -->
   <!-- Place the menu bar right here -->

   Thanks for visiting my web page. Please navigate with the menu bar above.
</html>

Thanks.


Edit: Though it might sound trivial, I wanted to make a few HTML pages to manage some of my personal files and data. As programmers, we of course do not like to repeat ourselves. My initial thought was that this was as simple as linking to a CSS file, but I see now it is more complicated, though I'm not sure (from a technical standpoint) why it has to be. In any case, since I'll be viewing the files on my own machine, I suppose I can install something like PHP to aid my efforts.

解决方案

You are describing server side includes.

Server Side Includes are useful for including a common piece of code throughout a site, such as a page header, a page footer and a navigation menu.

Example of usage:

<!--#include virtual="../quote.txt" -->

This will add the text of quote.txt to the page - if you add it to multiple pages, you can make your change in this one file and it will show on all pages in was included in.

Different web servers have different support and additional features for these, so you need to check the documentation for yours.


Many websites that need dynamic features (like fetching data from a database) will use some kind of server side scripting language for this kind of functionality - examples include PHP, Perl, ASP.NET, JSP and many more.

这篇关于HTML模板文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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