-2

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 class="navigationHeader">
    <nav>
      <div class="logo">
        <a href="index.html"><img src="images/BannerWhiteInvert.png" alt="2505 Marketing"
            style="height:60px; width:auto;"></a>
      </div>
      <ul class="nav-links">
        <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 class="burger">
        <div class="line1"></div>
        <div class="line2"></div>
        <div class="line3"></div>
      </div>
    </nav>
  </div>

  <script src="apps.js"></script>
  <div class="sidebar">
    <div class="sideIcons"><a href="https://youtube.com"> <img src="images/youtubeLogo.png" alt="Youtube"></a></div>
    <div class="sideIcons"><a href="https://instagram.com"> <img src="images/instagramLogo.png" alt="Instagram"></a>
    </div>
    <div class="sideIcons"><a href="https://facebook.com"> <img src="images/facebookLogo.png" alt="Facebook"
          style="width: 70%;"></a></div>
  </div>
  
  <div class="body-text">
    <div class="banner">
      <img class="logos" src="images/2505 banner clear.png" alt="logo">
    </div>
  </div>
  <div class="body-text">
    <div class="container">
</head>`
Neo
  • 1
  • 3
    best way -> **opinion-based** . I would search for templating methods. If your server supports PHP I would solve the issue with PHP. It does not require actual PHP. You still write your HTMl files in HTML just save them as `.php` then you can use `` to include another HTML file and let the HTML code snippets merge server sided – tacoshy Aug 12 '22 at 12:52
  • PS: Note, that the head is only for meta data not visual content. `head` !== `header`. As such your HTML markup is invalid! – tacoshy Aug 12 '22 at 12:53
  • I recommend to take a look at this link: https://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file –  Aug 12 '22 at 12:58
  • @BoTop this will not help to load the head element of a HTML document as it can't even load JS or Jquery at that point. YOu can no excute a script befor it even get's loaded You must use a server sided include. – tacoshy Aug 12 '22 at 13:04

2 Answers2

0

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)
Lalaluka
  • 910
  • 1
  • 11
  • 16
-1

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