Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 950375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:33:19+00:00 2026-05-15T23:33:19+00:00

At the moment, I have a base HTML template file. When ever I want

  • 0

At the moment, I have a base HTML template file. When ever I want to make a new page, I copy the template and place some require_once statements in between specific tags. I was wondering if there’s a better way that would make it unnecessary to copy the template each time. Here’s a typical example:

  <html>
   <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="css/second.css" />
    <script language="JavaScript" type="text/javascript"
        src="js/validation_functions.js"></script>
    <title>Order a Ticket for the ball</title>
   </head>
   <body>

    <div id="banner">St. Tom's Ambulance Ball</div>

    <!-- START[container] -->
    <!-- "body" -->
    <div id="container">

        <!-- START[header] -->
        <div id="header">

            <!-- header -->
            <div id="header_text">introduction</div>
            <div id="header_cell2">the process</div>
            <div id="header_cell3">start</div>

        </div>
        <!-- END[header -->

        <!-- START[content] -->
        <!-- "other container" -->
        <div id="content">

            <!-- START[form] -->
            <div id="form">
                <?php
                require_once(realpath($config["directories"]["views"]."/index.form.view.php"));
                ?>
            </div>
            <!-- END[form] -->

            <!-- START[data] -->
            <!-- "main content" -->
            <div id="data">
                <?php
                require_once(realpath($config["directories"]["views"]."/index.data.view.php"));
                ?>
            </div>
            <!-- END[data] -->

            <!-- START[side] -->
            <div id="side">
                <?php
                require_once(realpath($config["directories"]["views"]."/index.side.view.php"));
                ?>
            </div>
            <!-- END[side] -->

        </div>
        <!-- END[content] -->

        <!-- START[footer] -->
        <div id="footer">
            <!-- footer -->
            <div id="footer_text">
                <ul>
                    <li><a href="index.php">home</a></li>
                    <li><a href="">partners</a></li>
                    <li><a href="">projects</a></li>
                    <li><a href="">contact us</a></li>
                </ul>
            </div>

            <div id="footer_cell2">&nbsp;</div>
            <div id="footer_cell3">&nbsp;</div>

        </div>
        <!-- END[footer] -->

    </div>
    <!-- END[container] -->

  </body>
 </html>

EDIT: I have taken note of your suggestions to use GET. The new idea is to have each request url formed as index.php?page=page_name. This request would then be dealt with by a main controller which then sets the variables of the template based on the value of $_GET[‘page’]. For this, the template will now be:

  <html>
   <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="css/second.css" />
    <script language="JavaScript" type="text/javascript"
        src="js/validation_functions.js"></script>
    <title><?php h($title) ?></title>
   </head>
   <body>

    <div id="banner">St. Tom's Ambulance Ball</div>

    <!-- START[container] -->
    <!-- "body" -->
    <div id="container">

        <!-- START[header] -->
        <div id="header">

            <!-- header -->
            <div id="header_text"><?php h($header_1) ?></div>
            <div id="header_cell2"><?php h($header_2) ?></div>
            <div id="header_cell3"><?php h($header_3) ?></div>

        </div>
        <!-- END[header -->

        <!-- START[content] -->
        <!-- "other container" -->
        <div id="content">

            <!-- START[form] -->
            <div id="form">
                <?php
                require_once(realpath($view_1));
                ?>
            </div>
            <!-- END[form] -->

            <!-- START[data] -->
            <!-- "main content" -->
            <div id="data">
                <?php
                require_once(realpath($view_2));
                ?>
            </div>
            <!-- END[data] -->

            <!-- START[side] -->
            <div id="side">
                <?php
                require_once(realpath($view_3));
                ?>
            </div>
            <!-- END[side] -->

        </div>
        <!-- END[content] -->

        <!-- START[footer] -->
        <div id="footer">
            <!-- footer -->
            <div id="footer_text">
                <ul>
                    <li><a href="index.php">home</a></li>
                    <li><a href="">partners</a></li>
                    <li><a href="">projects</a></li>
                    <li><a href="">contact us</a></li>
                </ul>
            </div>

            <div id="footer_cell2">&nbsp;</div>
            <div id="footer_cell3">&nbsp;</div>

        </div>
        <!-- END[footer] -->

    </div>
    <!-- END[container] -->

  </body>
 </html>

Note: h() is a function that first of all removes all undesired entity tags before echoing a string.

On a related note, at the top of each page I have some controller files which are included with require_once. I was wondering if it would be possible to implement a function that simply includes files based on a specific input string (name of the functionality/page) i.e “index” in this way:

function include_controller($page){
  switch($page){
    case "index":
       require_once(realpath($config["directories"]["controllers"]."/index_.php"));
       break;
    case "checkout":
      require_once(realpath($config["directories"]["controllers"]."/checkout_.php"));
      break;
    default:
      break;
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:33:19+00:00Added an answer on May 15, 2026 at 11:33 pm

    Instead of hard coding the includes into each file, you could have a controller file in which you pass the page to be displayed through a $_GET variable. The controller then handles the logic and includes the appropriate page or pages. This is the way a lot of MVC frameworks do it.

    Edit: To answer your second question, instead of using a switch, you could just check to make sure the file exists. If it does, include that file, otherwise output an error (“Page doesn’t exists” or something similar).

    function include_controller($page){
        if (file_exists($config["directories"]["controllers"]."/$page_.php")) {
            // page exists, include it
            require_once($config["directories"]["controllers"]."/$page_.php"));
        } else {
            // page not found
        }
    }
    

    Obviously you should probably make the function a little more robust and probably limit the files that will be included to a certain directory or something. Also make sure you properly filter the $page variable so users aren’t able to access any file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base template file (base.html) and every other template extends to it
In the header region of my base template (main.html), I've placed an HTML5 media
At the moment I have setup a custom ok cancel dialog with a drop
At the moment I have a set of divs, generated dynamically by php and
Working on a project at the moment and we have to implement soft deletion
I have a self built JSP webapp and at the moment I'm using tomcats
I have a list view control which at the moment only allows one item
I have a weird error in my C++ classes at the moment. I have
I have a Java client that calls a web service at the moment using
For the moment the best way that I have found to be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.