【问题标题】:ASP.NET Master Page equivalent for HTML/PHP websites等效于 HTML/PHP 网站的 ASP.NET 母版页
【发布时间】:2012-08-12 15:20:45
【问题描述】:

我有一个网站,其中大部分内容(如侧边栏、背景等)在网站的大多数页面中都是相似的。

在 ASP.NET 中,对于这种情况,有母版页。 htmlphp 中的简单等价物是什么,易于使用? (从没用过php工具,网站是简单的html但主机是php服务器)

其次,有没有什么东西可以为用户避免下载多余的内容,加快速度?

【问题讨论】:

    标签: php html css


    【解决方案1】:

    这通常在 PHP 中通过包含来完成。查看include()include_once()require()require_once()

    您可以将页面的各个部分放在各自单独的文件中,并以这种方式单独管理它们。

    关于缓存,这只是setting the appropriate cache headers 的问题。最佳做法是将静态资源(JavaScript、CSS 等)保存在自己的单独文件中,以便更轻松地在您的网站中缓存它们。

    【讨论】:

      【解决方案2】:

      就我个人而言,我总是在 php 网站中使用 smarty.. 因为它为您提供了可能性,例如在 dot net 中将代码与标记分开。

      我通常会这样做

      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!
      

      ciao.tpl:

      hey there: ciao!
      

      通过这种方式,您可以创建用作页面(asp.net webform)的类和一个用作母版页等价物的类母版页。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-06
        • 2011-05-13
        • 2010-09-05
        • 2013-02-24
        • 1970-01-01
        • 2013-03-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多