问题
I am using Ganglia-web-frontend which is written in PHP. It uses template files to add personal headers/footers. I want to use an SSI set of pages that I have written, but the SSI code is not interpreted by apache.
more clearly, ganglia uses $tpl = new TemplatePower( template("$header.tpl") );
to include my header template file. In my header.tpl file I put : <!--#include virtual="/include/header.shtml" -->
which is my included file (and which works perfectly with my personal pages/scripts).
If look to the HTML code that I get in firefox (ctrl+U) I see that apache has included the SSI zone <!--#include virtual="/include/header.shtml" -->
as a commentary, and has not interpreded it.
I suppose there is something to do with the order in which things are interpreded/executed, but I cannot find the way to doing it work. Does anyone have an idea? I have root access to apache configuration too, if needed.
Thanks in advance
EDIT:
Following Sasha's suggestions I have tried to add
AddType text/html .tpl
AddHandler server-parsed .tpl
AddOutputFilter INCLUDES .tpl
to /etc/apache2/httpd.conf but this does not help. I don't get it...
EDIT 2 :
I guess it is maybe a problem with PHP TemplatePower module. But I cannot get it work. I have tried adding also $tpl->assignInclude( "header", "./header.tpl" );
in ganglia sources but this does not help.
回答1:
Is Apache configured to preprocess .tpl
files as Server-Side Includes? If not, it will ignore SSI directives in those files.
The section on 'Enabling Server-Side Includes' in the mod_include documentation has details on how to configure this. You'll need to ensure that .tpl
is present in the AddType
and AddOutputFilter
directives.
回答2:
You are loading the template as TemplatePower
template. So not apache is hosting that .tpl file but your script is, through that TemplatePower
object.
Therefore this is out of scope of the content-handlers and action-handlers of apache.
if you're running PHP as apache SAPI you can make use of the virtual() function.
You could then extend the templating engine to interprete those include virtual SSI commands and invoke the virtual()
function.
So the key point here really is that in the end Apache needs to execute the shtml template via a subrequest.
来源:https://stackoverflow.com/questions/23560326/ssi-included-in-php-as-template-not-working