简体   繁体   English

PHP中包含的SSI作为模板不起作用

[英]SSI included in PHP as template not working

I am using Ganglia-web-frontend which is written in PHP. 我正在使用用PHP编写的Ganglia-web-frontend 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. 我想使用我编写的SSI页面集,但是apache无法解释SSI代码。

more clearly, ganglia uses $tpl = new TemplatePower( template("$header.tpl") ); 更清楚地讲,神经节使用$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). 在我的header.tpl文件中,输入: <!--#include virtual="/include/header.shtml" --> ,这是我包含的文件(与我的个人页面/脚本完美配合)。

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. 如果查看我在firefox(ctrl + U)中获得的HTML代码,我会发现apache已将SSI区域<!--#include virtual="/include/header.shtml" -->作为注释,并具有不解释它。

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. 如果需要,我也有权访问apache配置。

Thanks in advance 提前致谢

EDIT: 编辑:

Following Sasha's suggestions I have tried to add 根据Sasha的建议,我尝试添加

AddType text/html .tpl 
AddHandler server-parsed .tpl
AddOutputFilter INCLUDES .tpl

to /etc/apache2/httpd.conf but this does not help. /etc/apache2/httpd.conf,但这无济于事。 I don't get it... 我不明白...

EDIT 2 : 编辑2:

I guess it is maybe a problem with PHP TemplatePower module. 我想这可能与PHP TemplatePower模块有关。 But I cannot get it work. 但是我无法使它工作。 I have tried adding also $tpl->assignInclude( "header", "./header.tpl" ); 我也尝试添加$tpl->assignInclude( "header", "./header.tpl" ); in ganglia sources but this does not help. 在神经节来源,但这无济于事。

Is Apache configured to preprocess .tpl files as Server-Side Includes? 是否.tpl Apache配置为预处理.tpl文件作为服务器端包含文件? If not, it will ignore SSI directives in those files. 如果不是,它将忽略那些文件中的SSI指令。

The section on 'Enabling Server-Side Includes' in the mod_include documentation has details on how to configure this. mod_include文档中有关“启用服务器端包含”的部分详细介绍了如何配置它。 You'll need to ensure that .tpl is present in the AddType and AddOutputFilter directives. 您需要确保AddTypeAddOutputFilter指令中存在.tpl

You are loading the template as TemplatePower template. 您正在将模板作为TemplatePower模板加载。 So not apache is hosting that .tpl file but your script is, through that TemplatePower object. 因此,不是Apache托管该.tpl文件,而是您的脚本通过该TemplatePower对象托管。

Therefore this is out of scope of the content-handlers and action-handlers of apache. 因此,这超出了Apache的内容处理程序和动作处理程序的范围。

if you're running PHP as apache SAPI you can make use of the virtual() function. 如果您将PHP作为apache SAPI运行,则可以使用virtual()函数。

You could then extend the templating engine to interprete those include virtual SSI commands and invoke the virtual() function. 然后,您可以扩展模板引擎以解释其中包括虚拟SSI命令的那些,并调用virtual()函数。

So the key point here really is that in the end Apache needs to execute the shtml template via a subrequest. 因此,这里的重点实际上是,最终Apache需要通过子请求执行shtml模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM