I'm trying to incorporate something like Masterpages into a website, and have been wondering about something.
Should you have one template site where you require the header, footer and content(by passing a variable which points to a content file).
example of template.php:
require(header.php);
require($content.php);
require(footer.php);
or should you just require the header and footer template in every site.
example of sonething_site.php:
require(header.php);
//content here
require(footer.php);
Thanks
What are master pages? Master pages are used to create consistency from page to page in a document. Master pages typicially contain page headers, footers, margin and column guides, and other elements that occur on multiple pages in your document.
The master page establishes a layout and includes one or more ContentPlaceHolder controls for replaceable text and controls. The content page includes only the text and controls that are merged at run time with the master page's ContentPlaceHolder controls.
A master page is a defined set of formatting that is applied to the sections of your document-style report. In a template, you can specify a master page that includes a header element, a footer element, and layout properties, such as orientation and borders.
A master page is an ASP.NET file with the extension . master (for example, MySite. master) with a predefined layout that can include static text, HTML elements, and server controls. The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary . aspx pages.
Simple Solution would be to have a file for master page and then calling it from your other pages, if you do not want to use any third-party template engine.
Example: master.php
<html>
<head>
<title>Title at Masterpage</title>
</head>
<body>
<div id="menu">
<a href="index.php">Home</a>
<a href="about.php">About Us</a>
<a href="contact.php">Contact Us</a>
</div>
<div><?php echo $content; ?></div>
<div id="footer">Footer to be repeated at all pages</div>
</body>
</html>
In your page for example about.php
<?php
$content = 'This is about us page content';
include('master.php');
?>
NOTE: If you want to have page contents in a separate file rather than setting $content variable, you can include the file in your page and assign it to $content. Then in master.php use include($content)
instead of echo $content
your first approach $content.php
doesnt seem very secure, i can insert my remote page there.
So your second approach is better, take a look at smarty. it s a great template engine.
and be careful!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With