将html源拆分为多个文件 [英] Split html source into multiple files

查看:150
本文介绍了将html源拆分为多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML支持在多个文件上拆分源吗?我正在寻找一些相当于C ++的 #include ;或者像C#的部分;一个可以获取源路径并在该位置注入文件内容的元素。

Does HTML support splitting source over multiple files? I'm looking for some equivalent of C++'s #include; or maybe something like C#'s partial; an element that could take source path and inject the file contents at that place.

如果之前已经询问过此道歉。谷歌和搜索引擎优化搜索没有太多回报。我不是网络人,但我找到的唯一解决方案是使用 iframe ,许多人因各种原因不喜欢这种解决方案。

Apologies if this has been asked before. Google and SO searches didn't return much. I'm not a web guy, but the only solution I found was using an iframe, which many people do not like for various reasons.

只是我的html源变得越来越大,我想通过拆分成多个文件来管理它。

It is just that my html source is becoming huge and I want to manage it by splitting into multiple files.

推荐答案

如果您正在运行PHP,很容易实现:

It is easily possible, if you are running PHP:

PHP语言内置了include命令。
因此你可以拥有你的index.php(注意你必须更改后缀,让PHP解析器启动)并简单地使用以下语法。

The PHP Language has the "include" command built in. Therefore you can have your "index.php" (note you have to change the suffix, for the PHP parser to kick-in) and simply use following syntax.

<html>
  <head>
    [...] (header content you want to set or use)
  </head>
  <body>
    <?php
      include "relative/path/to/your/firstfile.html";
      include "relative/path/to/your/secondfile.html";
      include "relative/path/to/your/evenwithothersuffix/thirdfile.php";
      include "relative/path/to/your/fourth/file/in/another/folder.html";
    ?>
    [...] (other source code you whish to use in the HTML body part)
  </body>
</html>

基本上使你的主要index.php文件成为容器文件和包含的html文件组件,你喜欢单独保持。

Basically making you main index.php file a container-file and the included html files the components, which you like to maintain seperately.

为了进一步阅读,我推荐 PHP手册 W3Schools Include 页面。

For further reading I recommend the PHP Manual and the W3Schools Include Page.

这篇关于将html源拆分为多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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