1

I've been asked to develop some simple views for an e-commerce website, but I can not use any framework, just raw HTML and CSS. My problem is that I do not want to repeat the navigation bar and footer code in each view. I am used to developing with Ruby on Rails, where I can solve this issue using partials.

Is there anything similar for this case or do I have to include the same code in each view (just because HTML is a static language)?

Thanks in advanced

tulians
  • 439
  • 5
  • 23

2 Answers2

0

This is where it can be useful to have a build script like gulp. Generally the process for things like static web pages is using a templating language like Jade or Handlebars. With Jade, you could just write something like this:

html
   body
      include ./includes/header.jade

Then compile it using gulp

var jade = require('gulp-jade');

gulp.task('templates', function() {
  var YOUR_LOCALS = {};

  gulp.src('./lib/*.jade')
    .pipe(jade({
      locals: YOUR_LOCALS
    }))
    .pipe(gulp.dest('./dist/'))
});

Other than a build step, however, there is no way to repeat static content using pure HTML and CSS.

Jack Guy
  • 8,346
  • 8
  • 55
  • 86
-1

You can create a separate footer and header html file then include them on your pages using php include like this <?php include 'header.html';?> and <?php include 'footer.html';?>

Just and them inline your main.html page wherever you want to add them.

or you can use Jquery like this:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#includedContent").load("footer.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>
Adam Buchanan Smith
  • 9,422
  • 5
  • 19
  • 39