簡體   English   中英

如何將Varnish ESI與模塊化PHP模板系統一起使用

[英]How to use Varnish ESI with modular PHP templating system

我希望將清漆實現為以數據為中心/以用戶為中心的網站。 如何使用使用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
?>

您只需要為您的特定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--

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM