1

我使用服务器端包含来组织我的文件。

嵌套文件似乎不起作用。例如:-

index.shtml - 这很好用

<!doctype html>
<html lang="en">
    <!--#include virtual="partials/head.shtml"-->
<body>
<!--#include virtual="partials/components/ads/horizontal-banner.shtml"-->
<div id="site-wrapper">
    <header id="site-header">
        <!--#include virtual="partials/header.shtml"-->
    </header>

    <div id="site-body">
        <!--#include virtual="partials/pages/home.shtml"-->
    </div>

    <footer id="site-footer">
        <!--#include virtual="partials/footer.shtml"-->
    </footer>
</div>
<!--#include virtual="partials/common.shtml"-->

home.shtml中,还有另一个调用

<!--#include virtual="../components/newsletter.shtml"-->

以下是项目结构:-

project
 - css
 - assets
 - js
 - partials
   - components
      - ads
        horizontal-banner.shtml
        vertical-banner.shtml
      newsletter.shtml
      help.shtml
   - pages
      home.shtml
      about.shtml
   header.shtml
   footer.shtml
   head.shtml
   common.shtml
index.shtml
4

1 回答 1

0

查看 Apache 的文档 -服务器端包括

对页眉和/或页脚使用包含文件可以减轻这些更新的负担。您只需制作一个页脚文件,然后使用 include SSI 命令将其包含到每个页面中。include 函数可以通过文件属性或虚拟属性确定要包含的文件。file 属性是相对于当前目录的文件路径。这意味着它不能是绝对文件路径(以 / 开头),也不能包含 ../ 作为该路径的一部分。virtual 属性可能更有用,并且应该指定一个相对于所服务文档的 URL。它可以以 / 开头,但必须与所服务的文件位于同一服务器上。

尝试像这样更改home.shtml

<!--#include virtual="partials/components/newsletter.shtml"-->

.. 并且newsletter.shtml文件应该以类似的方式进行更改。

于 2017-05-23T22:38:41.293 回答