亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

PHP
墨色風雨 2022-01-08 16:28:08
我正在尋找將清漆實施到數據重/以用戶為中心的網站中。如何使用使用 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--


查看完整回答
反對 回復 2022-01-08
  • 1 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號