Get started with jsrender CDN

MIT licensed

JsRender is a JS templating engine for rendering HTML markup from data.

Tags:
  • jsrender
  • node
  • express
  • hapi
  • browserify
  • templates
  • template

Stable version

Copied!

How to start using jsrender CDN


// Include JsRender library
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/jsrender/1.0.13/jsrender.min.js';
document.head.appendChild(script);

// Wait for JsRender to load
JsRender.ready(function() {
  // Prepare data
  const data = {
    name: 'John Doe',
    age: 30,
    hobbies: ['reading', 'swimming', 'coding']
  };

  // Define template
  const template = `
    <ul>
      <li>Name: {{: name }}</li>
      <li>Age: {{: age }}</li>
      <li>Hobbies:</li>
      <ul>
        {{for hobby in hobbies}}
          <li>{{: hobby }}</li>
        {{/for}}
      </ul>
    </ul>
  `;

  // Compile template
  const compiledTemplate = JsRender.compile(template);

  // Render data to HTML
  const output = compiledTemplate(data);

  // Append rendered HTML to the body
  document.body.innerHTML += output;
});
Copied!
Copied!
Copied!

All versions