Answer the question
In order to leave comments, you need to log in
What tool to connect the header and footer of the site?
I study layout. In this regard, I ask you to suggest / help or share your experience, how and with what tool do you connect the header or footer to the body of the site?
What is my difficulty? When laying out a multi-page site, it becomes problematic to write any link in the footer or footer, and in general, any change becomes a pain, you have to change it everywhere. Surely there is a solution, please share it.
I am currently learning HTML and CSS.
Answer the question
In order to leave comments, you need to log in
Start with SSI (Server Side Includes) - google it.
An example for you. The files must be in html, but with the .shtml extension:
1. Create the main file, header and footer files. For example, index.shtml, header.shtml, footer.shtml.
2. In the main file, right inside the html layout, we write:
<!--#include file="header.shtml"-->
...and the contents of the header file will be inserted there.
3. In the same place below:
<!--#include file="footer.shtml"-->
...and the contents of the footer file will be inserted there.
At least for training on simple training sites - that's it.
Deadly fast and no programming)
Good luck!
You can use nunjucks. There, in addition to include, there are variables, cycles and various other nice things. And the syntax stays the same
Just like that, without additional tools, in a natural way, html cannot import other html into itself, But!
You can take some collector of your code, for example gulp , configure it to take your files from one folder and put them in another
. Also add the gulp-rigger package to the assembly , after that you can use the construction inside your html files, like:
<body>
//= templates/header.html
<div>
...
</div>
//= templates/footer.html
</body>
I don't bother with faucets and use this method on js. It has its drawbacks, but in general it solves the problem.
<script>
function includeHTML() {
var z, i, elmnt, file, xhttp;
/* Loop through a collection of all HTML elements: */
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("w3-include-html");
if (file) {
/* Make an HTTP request using the attribute value as the file name: */
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {elmnt.innerHTML = this.responseText;}
if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
/* Remove the attribute, and call this function once more: */
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/* Exit the function: */
return;
}
}
}
includeHTML();
</script>
<div w3-include-html="header.html"></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question