3

Is there a way I can include include files inside include files? (Say that five times fast!)

For example:

Inside index.html:

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

Inside include1.shtml:

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

So the tree looks like this: index.html <-- include_1.shtml <-- include_2.shtml

As is, this is not working on my Apache. The first include works fine, but the content for the nested include doesn't display.

As it is relevant, I am using the XBitHack on Apache 2, and I've double checked that both files are executable by the web user.

Help?

neezer
  • 19,720
  • 33
  • 121
  • 220
  • 1
    I'm so glad you asked this question, I've always included include files (heh, it is tricky to say) named .htm. And I tried to nest another include inside an .htm file and it didn't work, and it never occurred to me (though it obviously should have) that that file needed the right extension. So, mega thanks from the future... – Michael Davis Apr 26 '11 at 19:40

2 Answers2

4

I know that this question is more than four years old, but for the benefit of people who, like me, find it thanks to StackOverflow's amazing search engine juice, here's how I made it work.

Under Apache2, you need to know this.

Relevant text:

This command inserts the text of the included file into the parsed file. SSI files may be nested, that is the included file may contain additional SSI statements (but in this case must have an .shtml suffix irrespective of the setting of XBitHack).

(Emphasis mine) For me, the solution lay in uncommenting two lines in the default httpd.conf:

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

… and changing the filename extension of the first-level included file to .shtml:

index.html
  └─┬─ include1.shtml
    └─── include2.html

Boom! Nested SSI works like a champion.

Dave Land
  • 2,257
  • 1
  • 18
  • 21
1

Make sure that Apache is actually trying to process the *.shtml files. Try putting

<!--#echo var="DATE_LOCAL" -->

in a *.shtml file and seeing if you get the expected results. Do you get the same result in a *.html file? If you don't see the dates in both, your configuration is off.

John Feminella
  • 303,634
  • 46
  • 339
  • 357
  • Yes, Apache is parsing .shtml files, but only one level deep. It is not parsing them two or more levels deep. That's my issue. – neezer Mar 17 '09 at 19:05
  • That's not what your post says -- you have an *.html file that gets parsed, not an *.shtml file. So it is suspicious that it stops at *.shtml. – John Feminella Mar 17 '09 at 19:51