我正在尋找將清漆實施到數據重/以用戶為中心的網站中。如何使用使用 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 頁面中包含 html 片段的 esi 標簽?與此類似:<?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 contentinclude("templates/content.html.php"); //no esi here, since page is dynamic contentinclude("templates/footer.html.php"); //esi would go here since page is static content?>
1 回答

慕萊塢森
TA貢獻1810條經驗 獲得超4個贊
您只需要為您的特定 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--
- 1 回答
- 0 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消