Greetings, everyone!
I'm new to web-development and have a lot of naive questions :) Right now I'm writing a simple site with very basic interface: the header, menu and content.
The content is the only thing that changes throughout the site. What I want to achieve is have all the HTML-code except content and head-tag in one place, so I don't have to edit each and every file when I need to update interface. So I want a single HTML-file for interface and a bunch of content-files.
So far I have only come up with writing a PHP-script that would read respective files and generate the output HTML-code. Of course, I would still have to make numerous of similar PHP-files but it doesn't really worry me because, unlike interface, I will no longer need to get back to it once it's done. But isn't it a serious compromise in terms of performance?..
I'm pretty sure there must be a standard solution but I can't seem to find an appropriate search request so I could google it.
Thanks in advance!
3 7044 kovik 1,044
Recognized Expert Top Contributor
Standard? Eh. The "standard," at least among newer programmers (and WordPress), is to store the header in a file (header.php) and the footer in a file (footer.php) and include them around the content in other files.
Personally, I like to create a template and insert data into the template. A simple way is to make a file that has a few variables it needs (such as $title and $content) and then the site files would define these properties.
Like so:
template.php - <html>
-
<head>
-
<title><?php echo $title; ?> - Site Name</title>
-
</head>
-
<body>
-
<div id="header">
-
<h1><?php echo $title; ?></h1>
-
<ul id="nav">...</ul>
-
</div>
-
<div id="content">
-
<?php echo $content; ?>
-
</div>
-
<div id="footer">
-
Copyright © 2010 Site Name
-
</div>
-
</body>
-
</html>
index.php - <?php
-
$title = 'Home';
-
ob_start();
-
?>
-
Welcome!
-
-
This is the content for the index.php file.
-
We use output buffering (http://php.net/manual/en/ref.outcontrol.php)
-
in order to store this data into a variable named "$content."
-
<?php
-
$content = ob_get_contents();
-
ob_end_clean();
-
-
include 'template.php';
Thanks, worked perfectly for me!
kovik 1,044
Recognized Expert Top Contributor Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brian Lin |
last post by:
Hi all,
I have a table called Category and it has only two fields: CategoryID
and CategoryName. I want user to be able to enter 10 categories at one
page. So I what I do right now is to place 10 text input boxs on the
page with name txt1, txt2, txt3, etc. After the user submit. I will
check to see if each txt box is empty and insert into table if not.
The problem is that I need duplicate the code for each text box. I am
wondering if...
|
by: shuisheng |
last post by:
Dear All,
Assume there are three classes where CA has members of class CA1 and
CA2 as follows. To make the public functions of CA1 and CA2 can work on
the members a1 and a2 in a CA object, I just write all the functions
such as a1_func1(), a1_fun2(), a2_func1(), as_func2() in the CA
interface. I think this is a stupid way since if there are more
functions in CA1 and CA2, I need to repeat them all. Is there any good
way to implement it?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |