I have a website for personal use. I need to move the upper part and sidenav-menu to a separate file and simply link to it on all pages, as I will need to add new buttons to the menu in the future. I’m completely new to website creation, so I don’t understand how to do it. (I am use Materialize)
I have no experience, and have literally 0 idea how to make it
2
Answers
Can you provide more info about your project?
Materialize is just a CSS Framework, but we need to know which framework web you are using and so on…
Your question is a bit vague but what I can understand from it is that you want to create a separate file for a nav bar and link it to different pages instead of adding the same code to each page.
If you’re using JavaScript, you can create a separate file for your navbar, like navbar.html, and then use JavaScript to fetch and insert it into your pages.
The below steps are considering a file called
navbar.html
but should work for yoursidenav-menu
file as well.In your project directory, create a new HTML file for your navbar. This file will contain the HTML and be linked to your Materialize CSS code. Below is what this file should look like:
navbar-injector.js
. This file will use the Fetch API to load the content of the navbar.html file and inject it into the placeholder contain. Below is the code:These steps should help you out but if you have any problems with it, feel free to comment and I’ll try to help out 🙂