How to include html files like include in php?

Viewed 4456

How can we include files inside html, like how we usually include files in Php.

<?php include "nav.php";?>
6 Answers

It's possible with webpack and html-webpack-plugin. This is index.html. You can create multiple files.

like this.

<%= require('html-loader!./views/partial/nav.html') %>

and here's more.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>Your Site Title</title>
  </head>

  <body>

    <%= require('html-loader!./views/partial/nav.html') %>

    <main id="mainDiv">
      <!-- Section Banner -->
      <%= require('html-loader!./views/partial/index/section-banner.html') %>

      <!-- Section Services -->
      <%= require('html-loader!./views/partial/index/section-services.html') %>

      <!-- Section About us -->
      <%= require('html-loader!./views/partial/index/section-aboutus.html') %>

      <!-- Section Call To Action -->
      <%= require('html-loader!./views/partial/index/section-call-to-action.html') %>

      <!-- Section Footer -->
      <%= require('html-loader!./views/partial/footer.html') %>
    </main>
  </body>
</html>
Related