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 312167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:59:28+00:00 2026-05-12T07:59:28+00:00

Most HTML in a large website is duplicated across pages (the header, footer, navigation

  • 0

Most HTML in a large website is duplicated across pages (the header, footer, navigation menus, etc.). How do you design your code so that all this duplicate HTML is not actually duplicated in your code? For example, if I want to change my navigation links from a <ul> to a <ol>, I’d like to make that change in just one file.

Here’s how I’ve seen one particular codebase handle this problem. The code for every page looks like this:

print_top_html();

/* all the code/HTML for this particular page */

print_bottom_html();

But I feel uncomfortable with this approach (partially because opening tags aren’t in the same file as their closing tags).

Is there a better way?

I mostly work with PHP sites, but I’d be interested in hearing solutions for other languages (I’m not sure if this question is language-agnostic).

  • 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-12T07:59:29+00:00Added an answer on May 12, 2026 at 7:59 am

    One solution at least in the case of PHP (and other programming languages) is templates. Instead of having two functions like you have above it would instead be a mix of HTML and PHP like this.

    <html>
      <head>
       <title><?php print $page_title ?></title>
       <?php print $styles ?>
       <?php print $scripts ?>
      </head>
    
      <body>
        <div id="nav">
          <?php print $nav ?>
        </div>
        <div id="content">
          <?php print $content ?>
        </div>
      </body>
    </html>
    

    Each variable within this template would contain HTML that was produced by another template, HTML produced by a function, or also content from a database. There are a number of PHP template engines which operate in more or less this manner.

    You create a template for HTML that you would generally use over and over again. Then to use it would be something like this.

    <?php
      $vars['nav'] = _generate_nav();
      $vars['content'] = "This is the page content."
      extract($vars);  // Extracts variables from an array, see php.net docs
      include 'page_template.php'; // Or whatever you want to name your template
    

    It’s a pretty flexible way of doing things and one which a lot of frameworks and content management systems use.

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

Sidebar

Related Questions

I am building an application where most of the HTML is built using javascript.
Given a html document, what is the most correct and concise regular expression pattern
I've got a php script. Most of the time the script returns html, which
i'm using this example implementation found at http://tangentsoft.net/wskfaq/examples/basics/select-server.html This is doing most of what
Most of my C/C++ development involves monolithic module files and absolutely no classes whatsoever,
Most of time we represent concepts which can never be less than 0. For
Most program languages have some kind of exception handling; some languages have return codes,
Most mature C++ projects seem to have an own reflection and attribute system ,
Most of the implementations I find require a hardware instruction to do this. However
Most of the MVC samples I have seen pass an instance of the view

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.