user1240679
user1240679

Reputation: 6979

ASP.NET Master Page equivalent for HTML/PHP websites

I have a website in which most of the content like the sidebar, the background etc. is similar across most of the pages in the sites.

In ASP.NET, for such a case there are master pages. What's the simple equivalent in html or php which could be easy to use? (never used php tools and the site is simple html but the host is a php server)

Secondly, Is there something that can avoid downloading the redundant content and speed up things for the user?

Upvotes: 2

Views: 1149

Answers (2)

bkwint
bkwint

Reputation: 626

Personally I always use smarty in php websites.. because it gives you the possibility, like in dot net to seperate code from markup.

I usually do something like this

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';
  }
}

and as template files i have something like this

masterpage:

<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!

this way you can create classes that function as pages (asp.net webform) and one class masterpage that functions as a masterpage equivalent.

Upvotes: 0

Brad
Brad

Reputation: 163303

This is typically done in PHP via includes. Check out include(), include_once(), require(), and require_once().

You can put various parts of your page in their own separate files and manage them separately this way.

Regarding caching, that is just a matter of setting the appropriate cache headers for what you are looking for. The best practices are to keep static resources (JavaScript, CSS, etc.) in their own separate files so they can more easily get cached across your site.

Upvotes: 2

Related Questions