{"id":29926617,"url":"https://github.com/ecomfe/smarty4js","last_synced_at":"2025-08-02T12:42:47.299Z","repository":{"id":57364085,"uuid":"42087381","full_name":"ecomfe/smarty4js","owner":"ecomfe","description":"a JavaScript template most like smarty, use smarty module in javascript","archived":false,"fork":false,"pushed_at":"2017-06-06T12:32:23.000Z","size":120,"stargazers_count":37,"open_issues_count":2,"forks_count":11,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-07-02T00:33:11.342Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecomfe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-08T03:15:37.000Z","updated_at":"2024-10-19T15:30:37.000Z","dependencies_parsed_at":"2022-08-29T13:40:11.711Z","dependency_job_id":null,"html_url":"https://github.com/ecomfe/smarty4js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ecomfe/smarty4js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsmarty4js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsmarty4js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsmarty4js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsmarty4js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomfe","download_url":"https://codeload.github.com/ecomfe/smarty4js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsmarty4js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268392180,"owners_count":24243297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-02T12:42:19.398Z","updated_at":"2025-08-02T12:42:47.261Z","avatar_url":"https://github.com/ecomfe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Smarty4Js (Smarty For JavaScript)\n======================================\n\n## What?\n\n- JavaScript template engine\n- Supports Smarty template syntax\n- Used in Node.js\n- Simple and powerful way to create and render a template\n\n## Why?\n\n- Powerful\n- Don't want to have two or more templates in your project\n- Deep love for Smarty\n\n## When?\n\n- When your synchronous templates is Smarty, and your Ajax templates will use the same template\n- When you want to write Smarty templates with JavaScript anywhere\n- When you want to put a lot of logic in JavaScript templates\n- When you like Smarty very much\n    \n## How?\n\n- Single\n- With Grunt\n- With Gulp\n- With EDP\n- With all Node.js web subject\n\n\n### Usage\n\n#### Install\n```bash\n    npm install -g smarty4js\n```\n\n#### Syntax\n```\n    Most of Smarty syntax is supported.\n```\n\n#### Command line\n ```bash\n    // get tpl.js\n    smarty4Js compile a.tpl [b.tpl ...] [-c|--config=confPath -o|--output=outputPath]\n        -c | --config: Use user-define config file\n        -o | --output: Specify a destination directory\n\n    // get tpl.html\n    smarty4Js render a.tpl [b.tpl ...] -d|--data=jsonFilePath [-c|--config=confPath -o|--output=outputPath]\n        -d | --data  : JSON data file path to render\n        -c | --config: Use user-defined config file\n        -o | --output: Specify a destination directory\n\n    // show current version\n    smarty4Js -v|--version\n\n``` \n\n- if `render`, return html(`demo.tpl.html`), if `compile`, return jsTpl(`demo.tpl.js`)\n- jsTpl is a closure. It has a `render` method that you can use:\n\n```Javascript\n    \n    // amd and cmd\n    var template = require('demo.tpl');\n    template.render(data);\n\n    // you can also use \u003cscript\u003e\n\n```\n\n#### used in Node.js\n```javascript\n    // get Smarty class\n    var Smarty = require('smarty4Js');\n\n    // create a Smarty object\n    var s = new Smarty();\n\n    // if you want to reset smarty config, you can do like this\n    var s = new Smarty({\n        'left_delimiter': '{%', // default\n        'right_delimiter': '%}', // default\n        'isAmd': false,\n        'isCmd': false,\n        'globalVar': '_smartyTpl' // window._smartyTpl is jsTpl object\n    });\n\n    // also, you can use `s.config()` method to config smarty before do compile operation\n    s.config({\n        'left_delimiter': '{%', // default\n        'right_delimiter': '%}', // default\n        'isAmd': false,\n        'isCmd': false,\n        'globalVar': '_smartyTpl'\n    })\n\n    // if compile source is template code and have `include, extend...` sentence in code\n    // you must give a path by `setBasedir` method\n    s.setBasedir(path);\n\n    // get compiler\n    // `tpl` param is template code or template file path\n    var compiler = s.compile(tpl); \n\n\n    // get ast\n    var ast = s.ast;\n\n    // get js code\n    var js = compiler.getJsTpl();\n\n    // render Smarty with data (3 methods)\n    var html = compiler.render(data);\n\n    // `tpl` param is template code or template file path\n    var html = s.render(tpl, data);\n\n    var html = (new Function('return ' + js)()).render(data);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fsmarty4js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomfe%2Fsmarty4js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fsmarty4js/lists"}