Sunday, March 30, 2014

Med size static site (50+ pages) needs nav update. Really? jQuery take me way.

50+ static pages. They were originally done using Dreamweaver templates, so technically they weren't static, but the who knows where the template files are now. I'm sure that was done years ago.

Now, how to update efficiently and make it easy for next time?

I didn't want to switch all the files to PHP and use includes, as there could be a lot of link issues and bookmarked pages. I could do some htaccess magic to account for that, but I really don't have the time to do it, and it's not really the "ask".

Instead I went for some simple JS includes. To more more specific, jQuery html(). Should I have used plane old innerHTML? Not sure.

For the nav, I assiged each line to a variable.

var nav_content = '<a href="index.html">Home</a>'';
nav_content += '<a href="about.html">About</a>'';
etc.

$('#main_nav').html(nav_content);

I added a linked JS file to each page, so now I can make global updates with JS.

No comments:

Post a Comment