Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ljs-template

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ljs-template

Lighter Javascript Templates

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Lighter Javascript Templates

Derived from EJS Embedded Javascript Templates with new expressions for lighter templates

How-To

Install

npm install ljs-template --save

Render

var ljs = require('ljs-template');

var out = ljs.render("Hello {{_name_}}", {name: "Max"});

console.log(out);

It displays:

Hello Max

Sample

Template :

var template = `

<h1>Books:</h1>

{#each books as book #}
<h2>{{_book.title_}}</h2>
<ul>
  <li>Authors:
   {#if book.authors #}
    <ul>
    {#each book.authors as author #}
      <li>{{_author_}}</li>
    {/each/}
    </ul>
   {/if/}
  </li>
  <li>Price: {{_book.price_}}
</ul>
{/each/}

`;

Data :

var data =
{
  books: [
    {
      title: "Cravings: Recipes for All the Food You Want to Eat",
      authors: ["Chrissy Teigen", "Adeena Sussman"],
      price: "$17.85"
    },
    {
      title: "Pretty Happy: Healthy Ways to Love Your Body",
      authors: ["Kate Hudson"],
      price: "$15.89"
    }
  ]
}

Render :

var ljs = require('ljs-template');

var out = ljs.render(template, data);

console.log(out);

It displays:

<h1>Books:</h1>
<h2>Cravings: Recipes for All the Food You Want to Eat</h2>
<ul>
  <li>Authors:
    <ul>
      <li>Chrissy Teigen</li>
      <li>Adeena Sussman</li>
    </ul>
  </li>
  <li>Price: $17.85
</ul>
<h2>Pretty Happy: Healthy Ways to Love Your Body</h2>
<ul>
  <li>Authors:
    <ul>
      <li>Kate Hudson</li>
    </ul>
  </li>
  <li>Price: $15.89
</ul>

Expressions

Javascript code :

{%
  [javascript]
%}

Define variable :

{#var [variable] = [javascript] #}

Display variable :

{{_[variable]_}}

If conditional :

{#if [condition] #}

{/else/}

{/if/}

Loop over Map entries :

{#each [map] as [value], [key] #}
{/each/}

Loop over Array values :

{#each [array] as [value], [index] #}
{/each/}

Keywords

FAQs

Package last updated on 17 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc