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

render-html-async

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

render-html-async

This is a template render engine. This is very light. This engine substitutes the query string parameters inside the html page and renders it

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

render-html-async

vesrion 0.0.5 License MIT

This is a template render engine. This is very light. This engine substitutes the query string parameters of url to inside the html page and renders it

Usage

HTML page

observe {{key}} symbol they contain keys of url querystring.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>Document</title>
    </head>
    <body>

        <h1>{{name}}</h1>
        <h1>{{age}}</h1>


    </body>
    </html>

method renderHTML

Method renderHTML takes two arguments and callback

  1. path path arguments is physical path in folder.

  2. url a. This could be querystring ?name=Umesh&age=45&gender=male

    b. This couild object i.e {name : "umesh", age : 45, gender : "male"} in above example name and gender are keys {{key}} is key of arguments these get replaced after rendering

  3. callback This is call function with err as first argument and data as second argument( html string);

  4. partials are also added. see below

    var render = require("render-html-sync");//include in your module

    test.renderHTML(__dirname + "/index.html", url, function(err, data){
    if(err){
        throw Error(err);
    }else{
        console.log(data);
    }
    })
    

method getParsedQueryString

This method returns json object from url with querystring

    var url = "./index?name=umesh&age=49";
    var queryJSON = render.getParsedQueryString(url);

method createQueryString

This method creates queryString from json object

    var jsonobj = {"name" : "Anthony", "age" : 35, "sex" : "nale"}
    var queryString = render.createQueryString(jsonOBJ);

Partials

First add Partials

    test.addPartials("header", __dirname + "/header.html");
    test.addPartials("footer", __dirname + "/footer.html");

create html partials(templates)

  1. header Partial {{get(header)}}
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>Document</title>
    </head>
    <body>

  1. footer Partial {{get(footer)}}
    </body>
    </html>
  1. acutual page with conatin this code
{{get(header)}}
<h1>{{name}}</h1>
<h1>{{age}}</h1>
{{get(footer)}}
  1. call render method
    test.renderHTML(__dirname + "/index.html", url, function(err, data){
    if(err){
        throw Error(err);
    }else{
        console.log(data);
    }
    })

Keywords

FAQs

Package last updated on 30 Apr 2018

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