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

smarty4js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smarty4js

A JavaScript Template Engine Most Like Smarty

  • 0.1.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36K
increased by4.32%
Maintainers
1
Weekly downloads
 
Created
Source

Smarty4Js (Smarty For JavaScript)

what?

  • JavaScript template engine
  • Support smarty template grammar
  • Used in nodejs
  • Simple and powerful way to creat and render a template

why?

  • Powerful
  • Don't want to have two or more template in your project.
  • Deep love smarty

when?

  • When your Synchronous template is Smarty ,and your ajax template will use the same template.
  • When you want to write smarty template with JavaScript anywhere.
  • When you want to put a lot of logic in JavaScript template
  • When you like smarty very much

how?

  • single
  • with grunt
  • with gulp
  • with edp
  • with all nodejs web subject

useage

install
    [sudo] npm install -g smarty4js
grammar
    most like smarty template grammar
command line
   // get tpl.js
   smarty4Js compile a.tpl [b.tpl ...] [-c|--config=confPath -o|--output=outputPath]
       -c | --config: Use user-define config file
       -o | --output: Specify a destination directory

   // get tpl.html
   smarty4Js render a.tpl [b.tpl ...] -d|--data=jsonFilePath [-c|--config=confPath -o|--output=outputPath]
       -d | --data  : json data file path for render
       -c | --config: Use user-define config file
       -o | --output: Specify a destination directory

   // show current version
   smarty4Js -v|--version

  • if render, return html(demo.tpl.html), if compile, return jsTpl(demo.tpl.js)
  • jsTpl is closure, hava a render method, you can use it like
    
    // amd and cmd
    var template = require('demo.tpl');
    template.render(data);

    // also could by <script>

used in nodejs
    // get Smarty class
    var Smarty = require('smarty4Js');

    // create a smarty object
    var s = new Smarty();

    // if compile source is template code and hava `include, extend...` sentence in code
    // you must give a dirpath by `setBasedir` method
    s.setBasedir(path);

    // get compiler
    // `tpl` param is template code or template file path
    var compiler = s.compile(tpl); 


    // get ast
    var ast = s.ast;

    // get js code
    var js = compiler.getJsTpl();

    // render smarty with data (3 methods)
    var html = compiler.render(data);

    // `tpl` param is template code or template file path
    var html = s.render(tpl, data);

    var html = (new Function('return ' + js)()).render(data);

Keywords

FAQs

Package last updated on 31 Aug 2015

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