0

I am wondering how can I send my header element over multiple pages. I have viewed the article and there are a lot of information, however it did not work in my case. I need more of understanding before I can implement the practices from the article. Can you please help me with more detailed explanation please? This is my code which I want to send over number of pages.

<header id = "header">
        <div class = "logo">
            Work Along
        </div>
        <div class = "pages">
            <a href = "index.html" id = "Gallery">Gallery Walls</a>
            <a href = "#contact">Story</a>
            <a href = "https://www.instagram.com/studio/" target = "_blank" class="fab fa-instagram" id = "icon"></a>
            <i class="fas fa-store" id = "icon"></i>
        </div>
    </header>
Aleksandre Bregadze
  • 199
  • 1
  • 3
  • 14
  • you could use php for instance to include the file across multiple pages. – Jonathan Akwetey Okine Aug 19 '20 at 15:11
  • php or ejs both great choices. Not the kind of thing you'll get a detailed answer for though, you're not showing any work or any of your progress. Place your question title in youtube and learn something. – Thanos Dodd Aug 19 '20 at 15:14
  • option A ) use html framesets (html < 5 only), Option B) use a client side rendering library like vue.js, angular or react, Option C) use a server side language like PHP, ASP etc – Dev Man Aug 19 '20 at 15:16

3 Answers3

1

This, does work effectively and rapidly. However, so use it but be critical as it might be always sensed.

Well, basically:

1a) go here https://releases.jquery.com/ ; 1b) from the last jquery Core version (i.e., I found the 3.6.4) click on "minified", right close to 'uncompressed', 'slim', 'slim minified'. You should find this line of code:

<script src="https://code.jquery.com/jquery-3.6.4.min.js" integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script>

2a) Now, before to use that code, create either a file called header.html and one called footer.html.

2b) In them, you have to paste respectively, the code you have to cut from your index.html, normally relative to the header and the footer, wrapped of course into the <header id="header"></header> tag and the <footer id="footer"></footer> one; at the end of this step, you must have created 2 new files reciprocally containing the mere code they are supposed to, wrapped into their tags. One doc for the header, with the header contents, and one for the footer, with only the footer content. (!!!soooo uselessly and redundantly clear, pwef!!!)

2c) Now that two new files ('header.html' and 'footer.html') have been created, save them in the same directory (or folder) where your index.html file is, or, wherever you do prefer accordingly;

Back now in the editor at our native index.html file, left with no header and footer!!! (The poor of him!).

3a) Let now then replace the cut code with the formula will bring back to life. So, take the code upon, obtained from jquery, and paste it just before the </head> of your doc.

3b) Just below, create (by writing it) another script coping the lines below, and mentioning your own id after $(' as well as placing the name of the your own previously created header file, in our example case, called 'header.html'.

<script>
     $(function(){ 
         $('#header').load('header.html');
         $('#footer').load('footer.html');
     });
</script>

3c) Now, right above the tag, paste the following code, in order to replace the previously cut <header></header> original code.

<div id="header"></div>

3d) Do the same for the footer, but placing the following line of code, at the end of the body, just before the tag.

<div id="footer"></div>

Do this operation for every HTML file you are going to create in your multi-page website

NB. when you create the header.html and footer.html file, do not forget to include the respective ids in the <header id="header"></header> and <footer id="footer"></footer> tags!

Recap:

  1. cut the header and create a files containing only the header code, included in the tags;
  2. do the same for the footer;
  3. paste both the jquery code and the relative script in each one of your your header-and-footerless HTML doc;
  4. custom the script with your IDs and file names;
  5. create a <div></div> which is wrapping the ID (see code in the example) in the area where before was laying your footer and header.

That is it. Enjoy!

Lego9430
  • 11
  • 5
0

I would Say PHP too with the include, in HTML there is a way, but it's not good to use it, iframes.

Anton
  • 59
  • 8
0

You could use JavaScript to create an HTML template and insert it inside body.

here is an example

// to put inside myHeaderFooterTemplate.js at the same level of your html pages 

// create a header 
let header = document.createElement('header');
//make the HTML template to insert inside your header 
let headerContent = `<h1>HTML Ipsum Presents</h1>
<nav><a href="#">link 1</a> <a href="#">link 2</a></nav>
<p>some more text to spray all over the site</p>`;
//insert the header right before anything else
document.querySelector('body').prepend(header);
// fill your header with HTML template
document.querySelector('body>header:first-of-type').innerHTML = headerContent;

// Now again with a footer:

let footer = document.createElement('footer');
document.querySelector('body').append(footer);


let footerContent = ` 
<nav><a href="#">link 1</a> <a href="#">link 2</a> <a href="#">link 3</a> <a href="#">link 4</a></nav>
<p>some more text to spray all over the site</p>`;


document.querySelector('body>footer:last-of-type').innerHTML = footerContent;
/* you can style those element added to your HTML alike anyother */
header,footer {background:#bee;border:solid 1px #0008;text-align:center;}
footer nav {display:flex;justify-content:space-around;border-bottom:ridge}
<script src="myHeaderFooterTemplate.js"></script>
<!-- let say this is index.html header and footer will be inserted via a javascript -->
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em>  Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
  tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>

<h2>Header Level 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
  elit sit amet quam. Vivamus pretium ornare est.</p>

Ressouces to understand what javascript does here :

and last how to link your javascript to your html document : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129