Socket
Socket
Sign inDemoInstall

stud

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    stud

A very simple and fast template engine for compiling and rendering HTML templates in an unopinionated fashion.


Version published
Weekly downloads
11
increased by450%
Maintainers
1
Install size
12.7 kB
Created
Weekly downloads
 

Readme

Source

Stud

A very simple and fast template engine for compiling and rendering pre-compiled HTML templates in an unopinionated fashion.

Installation

    
    npm install stud

Installation

    
    npm test

Usage in Node

Compiling and Rendering Templates with Stud

    var stud = require('stud'),
    data = {name:'steve', age:23, location:'US'},
    tmpl = "<td class='{name}'> {name} - {age} some of them are useful at location {location} as specified in the docs.</td>";
   
    /*The template will be registered with the name 'template_reg_name' */   
    var compiledTmpl = stud.compile(tmpl,'template_reg_name');  
    eval(compiledTmpl);
    
    /*
    * Alternatively, assynchronously
    var  = stud.compile(tmpl,'template_reg_name', function(compiledTmpl){
        eval(compiledTmpl);
    });  
    */
      
    
    
    stud.render('template_reg_name', data, function(rendered){
    
    /*here is the rendered template.*/
        console.log(rendered);
        
    }); 
       
    /*
       Alternatively,synchronously
       var rendered = stud.render('template_reg_name', data);
        
        console.log(rendered);
        
     */

Usage in Browser

Compiling and Rendering Templates with Stud

<!-- Include a copy of stud.js in the head section of your page -->
<script src='path/to/stud.js'></script>

    /* You stud in the global object, window in this case */
    
    var data = {name:'steve', age:23, location:'US'},
    tmpl = "<td class='{name}'> {name} - {age} some of them are useful at location {location} as specified in the docs.</td>";
   
    /*The template will be registered with the name 'template_reg_name' */   
    var compiledTmpl = stud.compile(tmpl,'template_reg_name');  
      
    eval(compiledTmpl);
    
    stud.render('template_reg_name', data, function(rendered){
    
    /*here is the rendered template.*/
    /*
    <td class='steve'> steve - 23 some of them are useful at location US as specified in the docs.</td>
    */
        console.log(rendered);
        
    });    
        

That is all to it. Have fun compiling and rendering with Stud.

Keywords

FAQs

Last updated on 13 Mar 2017

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