HTML5 import with sidebar menu


Leo Odishvili

I'm working on a project where I have very large sidebar menus for many pages, I really don't want to change it all the time on all pages, but I also don't want to use the php include() function.

Well, I went and used the html5 import. It does work, but I have a problem. My index.html is in the root folder, but users.html is in the root/pages folder. So.. when it goes there, it imports the same menu as in index.html, but that's wrong. Because the link is broken. For example, after that I can't access index.html because I need ../index.html but it writes index.html which is the js I use to import the file

var doc= document.querySelector('link[rel="import"]').import;
var text = doc.querySelector('template');
var clone = document.importNode(text.content, true);
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
console.log(dir);
document.querySelector('.sidebar-menu').appendChild(clone);
Abbott

If you change the link in the sidebar to an absolute path instead of a relative path it should work on any page. replace:

<a href="index.html">Home</a>

use this:

<a href="/index.html">Home</a>

The exact absolute paths may vary depending on whether you use folders /publicetc. , but once you get them working once, they will work on any page of your app.

Related


How to import google sheets if sidebar menu item is selected

Barrett So I'm going to build a single Shiny application. My goal is to try and bring in Google Sheets that is connected to our Salesforce database. I've abstracted this into Google Sheets and created charts and datasheets that refresh dynamically through our

How to import google sheets if sidebar menu item is selected

Barrett So I'm going to build a single Shiny application. My goal is to try and bring in Google Sheets that is connected to our Salesforce database. I've abstracted this into Google Sheets and created charts and datasheets that refresh dynamically through our

How to import google sheets if sidebar menu item is selected

Barrett So I'm going to build a single Shiny application. My goal is to try and bring in Google Sheets that is connected to our Salesforce database. I've abstracted this into Google Sheets and created charts and datasheets that refresh dynamically through our

HTML5 import not working

NoName84 I've been looking for a way to include an html file into another html file... For example, I have 3 html files... 1) header.html 2) content.html 3) footer.html... , I want to include header.html and footer.html in content.html so I can create multiple

HTML5 import not working

NoName84 I've been looking for a way to include an html file into another html file... For example, I have 3 html files... 1) header.html 2) content.html 3) footer.html... , I want to include header.html and footer.html in content.html so I can create multiple

Responsive sidebar push menu

innovation I have a question about responsive sidebar menu. First, I'll give you a demo from codepen.io If you change the width of the archer, you can see the green button in the upper right corner. When you click this button, the red background color div will

Responsive sidebar push menu

innovation I have a question about responsive sidebar menu. First, I'll give you a demo from codepen.io If you change the width of the archer, you can see the green button in the upper right corner. When you click this button, the red background color div will

Collapse Sidebar Menu Flex

Frado Galla I'm creating an admin panel for my website, I got the sidebar menu, I need to hide it to the hamburger icon and collapse it only when I click on it. I was looking for a solution but didn't find much. I hope you guys can help me with my problem. I g

Sidebar menu not showing?

creative learning After the login screen, I use the navigation bar to get to the home screen. But it creates some problems, if I come from the login screen, the "sidebar menu" doesn't open in the main screen. If I start from the navbar screen (not from the log

Responder Sidebar Menu

Luke I am very new to jQuery and I would like to change the following code to suit my needs: $(document).ready(function() { var slider_width = $('.pollSlider').width(); //get width automaticly $('#pollSlider-button').click(function() { if ($(this).cs

Dynamically update the menu in the sidebar

ushi I have a sideBar component that displays menu items. But the menu items keep changing based on the currently rendered page. How to update menu item from child component. app.js content const items = [ { path: '/home', label: 'Home' }, { path: '/ab

Sidebar menu for macOS in SwiftUI

Arturo I'm trying to implement a menu, here's what I have so far: Navigation view struct macOS_NavigationView: View { @State private var selectedTab: HostingBarCategories = .Screen1 var body: some View { NavigationView {

Collapsible sidebar/navigation menu

Sergi Fernandez I'm coding a website that has a navbar on it and a sidebar on the left. I wish to turn this fiddle into this one . It works with CSS, JQuery, JavaScript, and Bootstrap, and when you click the icon, the sidebar will drag out to the right. When y

Dynamic Sidebar Menu RShiny

It is clear I have a problem with my dashboard. I want to create a dynamic sidebar menu, but by default the menu items don't work. The user must click on it to display it. I found an example on this issue https://github.com/rstudio/shinydashboard/issues/71 but

Dynamic Sidebar Menu RShiny

It is clear I have a problem with my dashboard. I want to create a dynamic sidebar menu, but by default the menu items don't work. The user must click on it to display it. I found an example on this issue https://github.com/rstudio/shinydashboard/issues/71 but

Dynamically update the menu in the sidebar

ushi I have a sideBar component that displays menu items. But the menu items keep changing based on the currently rendered page. How to update menu item from child component. app.js content const items = [ { path: '/home', label: 'Home' }, { path: '/ab

Sidebar menu for macOS in SwiftUI

Arturo I'm trying to implement a menu, here's what I have so far: Navigation view struct macOS_NavigationView: View { @State private var selectedTab: HostingBarCategories = .Screen1 var body: some View { NavigationView {

Vuejs sidebar menu with children

Luis Alves I am trying to dynamically create a sidebar menu using vuejs and vuenotify. I saw an example using the following on the vuetify website. The problem with this code is that the additional icon ">" is always displayed at the end of the item title. I w

Sidebar menu collapsible CSS

Justin I've been looking for a tutorial on how to make a simple sidebar menu for a site that can be collapsed and expanded by clicking the home button next to the sidebar menu, just like in an app when you click it Open the main menu like the hamburger icon. I

Sidebar Navigation Menu on Storyboard

Marco Chiang I followed the TreeHouse tutorial on how to create a login/register screen and the AppCoda tutorial on adding a sidebar navigation menu : http://www.appcoda.com/ios-programming-sidebar-navigation-menu/ I attach the login/register bar to my main vi

CSS for collapsible sidebar menu

Justin I've been looking for a tutorial on how to make a simple sidebar menu for a website that can be collapsed and expanded by clicking the home button next to the sidebar menu, just like how an app is clicked on Open the main menu in the same hamburger icon

Responsive sidebar push menu

innovation I have a question about responsive sidebar menu. First, I'll give you a demo from codepen.io If you change the width of the archer, you can see the green button in the upper right corner. When you click this button, the red background color div will

Create a sidebar navigation menu

Bruno I want to create a menu in my sidebar navigation application. I try to create, but the result is never what I expected. Maybe the problem is with the library or some library is missing. Here's one of my doubts, I put together the library I'm using with t

Dynamically update the menu in the sidebar

ushi I have a sideBar component that displays menu items. But the menu items keep changing based on the currently rendered page. How to update menu item from child component. app.js content const items = [ { path: '/home', label: 'Home' }, { path: '/ab

Sidebar menu for macOS in SwiftUI

Arturo I'm trying to implement a menu, here's what I have so far: Navigation view struct macOS_NavigationView: View { @State private var selectedTab: HostingBarCategories = .Screen1 var body: some View { NavigationView {