2012-08-12 24 views
2

我有一個網站,其中大多數內容(如側邊欄,背景等)在網站中的大部分頁面中都是相似的。相當於HTML/PHP網站的ASP.NET主頁

在ASP.NET中,對於這種情況,有主頁面。什麼是htmlphp簡單的等價物,它可以很容易地使用? (從來沒有使用的PHP工具和網站是簡單的HTML,但主機是一個PHP服務器)

其次,有什麼可以避免下載多餘的內容和加快用戶的東西?

回答

2

這通常是通過包含在PHP中完成的。檢出include(),include_once(),require()require_once()

您可以將頁面的各個部分放在各自的獨立文件中,並以這種方式單獨管理它們。

關於緩存,這只是setting the appropriate cache headers你正在尋找的問題。最佳實踐是將靜態資源(JavaScript,CSS等)保存在各自獨立的文件中,以便他們可以更輕鬆地在您的網站上緩存。

0

就我個人而言,我總是在php網站中使用smarty ..因爲它給你的可能性,就像點網中的標記分離代碼。

我平時做這樣的事情

class masterpage 
{ 
    protected $subpage; 

    public function output() 
    { 
    $smarty = new Smarty(); 
    $smarty->assign('subpage', $this->subpage); 
    return $smarty->fetch('masterpage.tpl'); 
    } 
} 

class helloworld extends masterpage 
{ 
    public function __construct() 
    { 
    this->subpage = 'helloworld.tpl'; 
    } 
} 

class ciao extends masterpage 
{ 
    public function __construct() 
    { 
    this->subpage = 'ciao.tpl'; 
    } 
} 

和模板文件,我有這樣的事情

母版:

<html> 

<body> 
    <div>This is the menu that has to be on every page!!!!</div> 
    {include file="$subpage"} 
</body> 

</html> 

helloworld.tpl:

hey there: Hello world! 

再見.tpl:

hey there: ciao! 

這種方式,您可以創建的網頁起作用的類(asp.net的網頁表單)和一個母版類用作一個母版等同。