我希望将varnish实现为一个数据密集型/以用户为中心的网站。如何在使用php包含html模板的系统中设置ESI?
我目前使用的是一个自定义的php模板系统(类似于MVC设计模式),它的工作原理如下:
生成页面请求-> php计算逻辑-> php包括html模板页面并填充变量输出->页面
我只在大多数html页面中使用过esi标签,包括php代码片段。
如以下代码所示:
<HTML>
<BODY>
The time is: <esi:include src="/php-includes/date.php"/>
at this very moment.
</BODY>
</HTML>但是,是否可以反过来做呢?例如,在php页面中添加esi标签以包含html代码片段?
如下所示:
<?php
//logic here
$content = "this will be displayed on the content page"
include("templates/header.html.php"); //esi would go here since page is static content
include("templates/content.html.php"); //no esi here, since page is dynamic content
include("templates/footer.html.php"); //esi would go here since page is static content
?>发布于 2019-09-12 22:23:07
您只需为您的特定MVC实现创建一种"ESI“渲染器,就像在/esi.php?template=foo中一样,然后在下面这样的东西中:
... whatever you need to boostrap your app in order to render a template ....
include("templates/$template.html.php");
.... exit so no header/fooder stuff is rendered, only template HTML of interest当然不是那么简单,但简而言之,是一个类似的事情。
然后,我会在每个模板文件上放置一些逻辑,以便发出HTML (如果由esi.php呈现,或者如果ESI“功能”处于禁用状态)或仅发出<esi标记。
因此,例如,templates/header.html.php可以具有(伪代码):
if esi (detect by checking request_uri to be esi.php) then echo '<esi /esi.php?template=header?somevar-from-parent=...'; return
---existing code--https://stackoverflow.com/questions/57902569
复制相似问题