Templates

In this example below you will see how to do a Templates with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by adamaoc, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright adamaoc ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Templates</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
      <style>
      /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */
      #app {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.modal {
  padding: 1em;
  border: 1px solid #eee;
}

    </style>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>

</head>

<body>

  <div id="app">stuffs...</div>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/adamaoc/templates-bMxRVP */
#app {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.modal {
  padding: 1em;
  border: 1px solid #eee;
}


/*Downloaded from https://www.codeseek.co/adamaoc/templates-bMxRVP */
var app = document.getElementById('app');

var data = {
  title: "This title",
  content: "this content",
  open: true
};
var modalClass = "modal " + (data.open ? 'modal--open' : '');

console.log(modalClass);

var modal = "\n  <div class=" + modalClass + ">\n    <h2>" + data.title + "</h2>\n    <p>" + data.content + "</p>\n  </div>\n";

function render(node, html) {
  node.innerHTML = html;
}

render(app, modal);

Comments