Socket
Socket
Sign inDemoInstall

templ8

Package Overview
Dependencies
63
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    templ8

Just a simple templating engine


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
7.90 kB
Created
Weekly downloads
 

Readme

Source

#Templ8 This is a simple templating library for NodeJS It's made of the following items:

  • Templates
  • Containers/Content
  • Data

This library will basically replace template nodes by the specified source and will insert content into containers in the same way

##Example

###templates/index.html

<html>
  <template src="head"/>
  <body>
    <h1>Templ8</h1>
    <p>A pretty simple templating engine</p>
    <template src="navigation"/>
    <p>This is a container called index</p>
    <content>
    <template src="footer"/>
  </body>
</html>

###templates/head.html

<meta charset="utf8">
<title>Templating engine test</title>

###templates/navigation.html

<nav>
  <a href="">Home</a>
  <a href="">Link1</a>
  <a href="">Link2</a>
</nav>

###templates/example.html

<div>
  Here's an example on how to pass data
  <template src="someOtherCode"/>
  <p>See it in action:</p>
  <p>Hello! my name is {{user.name}}!</p>
</div>

###templates/someOtherCode.html

<pre>
  engine.render('index', {
    "user": {
      "name": "Sean"
    }
  });
</pre>

###templates/footer.html

<div>
  This is the footer
</div>

###Using express

var express = require("express"),
    app = express(),
    engine = require("templ8");

const PORT = 4000;

engine = new engine();

//Add HTML comments to show where templates begin and end
engine.verbose = true;

app.get("/", function (req, res) {
  
   engine.render('body', {
    "user": {
      "name": "Sean"
    }
  }).then(function (html) {
    res.setHeader('content-type', 'text/html');
    res.status(200).end(html);
  }).catch(function (err) {
    res.status(500).end(err);
  });
  
});

app.listen(PORT, function () {
  console.log('Example listening at', PORT);
});

##Todos

  • Use promises in file reading operations
  • Implement as an Express rendering engine

FAQs

Last updated on 01 Mar 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc