# js-template

> Rewritten and Improved John Resig's micro javascipt template

Latest version **0.1.4** (published 2015-08-23) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install js-template
pnpm add js-template
yarn add js-template
bun add js-template
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2015-08-23 |
| First published | 2015-08-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Allen Kim |
| Maintainers | allenkim |
| Keywords | template, micro, resig |

## Links

- npm: https://www.npmjs.com/package/js-template
- Repository: https://github.com/allenhwkim/js-template
- Issues: https://github.com/allenhwkim/js-template/issues
- npm.io page: https://npm.io/package/js-template

## Recent versions

- 0.1.4 (latest) — 2015-08-23
- 0.1.3 — 2015-08-17
- 0.1.2 — 2015-08-17
- 0.1.1 — 2015-08-15
- 0.1.0 — 2015-08-15

## README

# js-template
Rewritten and Improved John Resig's micro javascipt template

js-template is based on John Resig's microTemplate function. However the orinal version has got to be improved.

  - No more error with single quote
  - Better error message handling wth line number
  - No more scrambled output by keeping white spaces as it is
  - Less undefined variable errors
  - include feature. e.g. include('partial.html', data)

Install
-------

    npm install js-template

Example
--------

    var jsTemplate = require('js-template');
    var templateHtml = "Hello <b><%= world %></b>";
    var data = {world: "You!!"};
    var output = jsTemplate(templateHrml, data);
    console.log(output); // Hello <b>You!!</b>

#### template1

    <div id="<%= id %>" class="<%=(i % 2 == 1 ? "even" : "")%>">'
      <div class="grid_1 alpha right">
        <img class="righted" src="<%= profileImageUrl %>"/>
      </div>
      <div class="grid_6 omega contents">
        <a href="/<%= fromUser %>"><%= fromUser %></a>
      </div>
    </div>
    <% for (var i = 0; i < users.length; i++) { %>
      <a href="<%=users[i].url%>"><%= users[i].name %></a>
    <% } %>

#### data1

    {
      id: 'myid',
      i: 11,
      profileImageUrl: 'myurl',
      fromUser: 'me',
      users: [
        {name: "John", url: "john.com"},
        {name: "Jane", url: "jane.com"}
      ]
    };

#### jsTemplate(template1, data1)

    <div id="myid" class="even">
      <div class="grid_1 alpha right">
        <img class="righted" src="myurl"/>
      </div>
      <div class="grid_6 omega contents">
        <a href="/me">me</a>:</b>
      </div>
    </div>
      <a href="john.com">John</a>
      <a href="jane.com">Jane</a>

#### template2

    <div>
      <%= include("spec/test-include.html", data) %>
    </div>

#### data2

    {
      users: [
        {name: "John", url: "john.com"},
        {name: "Jane", url: "jane.com"}
      ]
    };

#### jsTemplate(template2, data2)

    <div>
      <a href="john.com">John</a>
      <a href="jane.com">Jane</a>
    </div>

---
_Source: https://npm.io/package/js-template · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
