Socket
Book a DemoInstallSign in
Socket

minitemplator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minitemplator

A compact, optimized template engine for HTML.

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

MiniTemplator - JavaScript Version

MiniTemplator is a compact, optimized template engine primarily used for generating HTML output.

Template syntax

Variables:

${variableName}

Blocks:

<!-- $beginBlock blockName -->
  ... block content ...
<!-- $endBlock blockName -->

Conditional statements:

<!-- $if condExpr -->
  ...
<!-- $elseIf condExpr -->
  ...
<!-- $else -->
  ...
<!-- $endIf -->

Include a subtemplate:

<!-- $include fileName -->

Principles

  • Blocks can be nested.
  • Subtemplates can include other subtemplates.
  • Conditions are JavaScript expressions that use condition variables.

Phases

There are two phases when using MiniTemplator templates.

Phase 1: Loading, parsing and caching

When a template is parsed, condition expressions are evaluated, conditional statements are resolved and subtemplates are included. A template is normally loaded and parsed only once and then used many times. A parsed template can be cached in memory for later re-use.

Phase 2: Output document buildup

In the second phase, template variables are set and blocks are added. When the document buildup is complete, everything is merged into a HTML string, which is the output of the template engine.

Variables

There are two kinds of variables.

Condition variables

Condition variables are used in $if and $elseIf statements.

  • Condition variables are used at the time a template is loaded and parsed.
  • For each set of condition variable values, a separate parsed template object is cached.

Template variables

Template variables are used to place content into the template.

  • Template variables are used when applying a parsed template to generate output.
  • When a template variable is used within a block, it must be set before the addBlock() method for the block is called.
  • The values undefined and null are converted into an empty string.

Short form for conditional statements

When the shortFormEnabled option is set to true, the following alternative form can be used for conditional statements:

<$? condExpr>
  ... content for "if" case ...
<$: condExpr>
  ... content for "elseIf" case ...
<$:>
  ... content for "else" case ...
<$/?>

Example:

<$?de> Hallo Welt!
<$:fr> Bonjour le monde!
<$:it> Ciao mondo!
<$:  > Hello world!
<$/?>

Keywords

Template engine

FAQs

Package last updated on 21 Apr 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.