如果您使用過ASP.NET MVC,那麼您會熟悉RenderBody。基本上,你有一個佈局頁面和幾個正文頁面。事情是這樣的:php中的RenderBody
layout.cshtml:
<html>
<head>
<title>Your Title</title>
</head>
<body>
@RenderBody()
</body>
</html>
index.cshtml:
@{
layout = "layout.cshtml";
}
<p>Hello World!</p>
所以,當你調用index.cshtml,它的所有內容都將在佈局的@RenderBody
部分被所示。當您的頁面使用單個佈局時,這非常有用。
現在,我的問題是,我怎麼能實現類似於上面的代碼在PHP中?
編輯
對於那些誰不熟悉ASP.NET,當你有一個index2.cshtml文件是這樣的:
@{
layout = "layout.cshtml";
}
<p>Hello World, once again!</p>
然後當你調用index2.cshtml這次「 Hello World,再一次!將被打印。所以基本上,當您定義頁面的佈局時,其所有內容都會顯示在其佈局的@RenderBody部分。您不必明確定義要在佈局中包含的頁面。
你是指不使用模板? –
對不起,我的意思是框架:) – Shaokan