Home > Software engineering >  what's the best way to link header across multiple pages
what's the best way to link header across multiple pages

Time:08-13

Hey guys I'm a beginner and currently my website is using this nav bar code on every page is there a way I can link this tag to other pages without repeating all this code on each page? There is a burger and a running sidebar popup. that hold their code in apps.js, currently every page of the project starts with this code, I would prefer to keep this code on index.html and import the to any new page I develop.

`<!DOCTYPE html>
<html lang="en">

<head>
  <title>About us</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="style.css">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <div >
    <nav>
      <div >
        <a href="index.html"><img src="images/BannerWhiteInvert.png" alt="2505 Marketing"
            style="height:60px; width:auto;"></a>
      </div>
      <ul >
        <br>
        <li><a href="index.html">Home</a></li>
        <br>
        <li><a href="packages.html">Pricing</a></li>
        <br>
        <li><a href="contactform.html">Contact</a></li>
      </ul>
      <div >
        <div ></div>
        <div ></div>
        <div ></div>
      </div>
    </nav>
  </div>

  <script src="apps.js"></script>
  <div >
    <div ><a href="https://youtube.com"> <img src="images/youtubeLogo.png" alt="Youtube"></a></div>
    <div ><a href="https://instagram.com"> <img src="images/instagramLogo.png" alt="Instagram"></a>
    </div>
    <div ><a href="https://facebook.com"> <img src="images/facebookLogo.png" alt="Facebook"
          style="width: 70%;"></a></div>
  </div>
  
  <div >
    <div >
      <img  src="images/2505 banner clear.png" alt="logo">
    </div>
  </div>
  <div >
    <div >
</head>`

CodePudding user response:

There are several Solutions for this Usecase.

To name a few:

  • Templating Methods: PHP, Pug/Jade, Handlebars
  • Static Site Generators (Like Hugo, Nuxt.js)
  • Single-Page Applications (Like Vue.js, React, Angular)

CodePudding user response:

without using any programming language you cannot use one component on multiple pages, I suggest, you should use React js which is a javascript library, that is very simple, where you can use one header or any one component in multiple pages, if you don't know about React js, reach me out I will help you

  • Related