{"id":15209271,"url":"https://github.com/timomeh/ejs-helper","last_synced_at":"2025-10-03T01:31:33.970Z","repository":{"id":57221129,"uuid":"34926979","full_name":"timomeh/ejs-helper","owner":"timomeh","description":"Template helper functions for ejs view engine","archived":true,"fork":false,"pushed_at":"2018-12-16T21:53:18.000Z","size":13,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-01-15T16:22:07.456Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timomeh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-01T22:28:08.000Z","updated_at":"2024-08-11T12:55:42.000Z","dependencies_parsed_at":"2022-08-29T00:11:36.141Z","dependency_job_id":null,"html_url":"https://github.com/timomeh/ejs-helper","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timomeh%2Fejs-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timomeh%2Fejs-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timomeh%2Fejs-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timomeh%2Fejs-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timomeh","download_url":"https://codeload.github.com/timomeh/ejs-helper/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235059234,"owners_count":18929279,"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","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":"2024-09-28T07:22:55.498Z","updated_at":"2025-10-03T01:31:28.684Z","avatar_url":"https://github.com/timomeh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EJS Helper\n\n\u003e **Hey, developer! This project is *unmaintained*. Since I'm not using EJS in any project anymore, I have no interest in maintaining it. Feel free to open a [Pull Request](https://github.com/timomeh/ejs-helper/pulls), if you'll want to fix something or add a fancy feature. kthxbye**\n\u003e \n\u003e Also a big thanks to [Andreas Galazis](https://github.com/agalazis) for adding new features from time to time.\n\n\u003ca href=\"https://www.npmjs.com/package/ejs-helper\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/ejs-helper.svg\" alt=\"ejs-helper on npm\" /\u003e\n\u003c/a\u003e\n\nEJS Helper is a collection of functions to have a better template including experience in [Express](https://github.com/strongloop/express).\n\nWorks with Express `4.x` and EJS `2.x`.\n\n## Installation\n\n```bash\nnpm install ejs-helper --save\n```\n\n## Usage\n\n### Express integration\n\n```js\nvar ejsHelper = require('ejs-helper');\n\napp.use(ejsHelper({\n    cssPath: '/static/css/',\n    jsPath: '/static/js/',\n    urlArgs: 'v='+requie(\"package.json\").version+'\u0026awesomeness=true'\n}));\n```\n\n### Template integration\n\nMost of the times you will have something like a `header.ejs` and `footer.ejs` which will be included in a `somePage.ejs` as a re-usable template. But sometimes you want to insert CSS- or JavaScript-Files into your header and/or footer from your `somePage`. Sending locals along `res.render()` is not the best solution.\n\nThis will be implemented like this:\n\n**header.ejs**\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003ctitle\u003e\u003c%= title() %\u003e\u003c/title\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n\u003c%- head();  -%\u003e\n\u003c%- scripts('header'); %\u003e\n\u003c%- styles(); -%\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n```\n\n**footer.ejs**\n\n```html\n\u003c%- scripts('footer'); %\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n**somePage.ejs**\n\n```html\n\u003c%\nsetTitle('Some Page');\naddHead('\u003cmeta name=\"description\" content=\"This is some page\"\u003e');\naddHead('\u003cmeta name=\"author\" content=\"Timo Mämecke\"\u003e');\naddStyle('style.css');\naddStyle('print.css', { media: 'print' });\naddScript('header', 'script1.js', { async: 'async' });\naddScript('footer', 'script2.js');\n%\u003e\n\u003c% include header %\u003e\n   \u003ch1\u003eLorem ipsum\u003c/h1\u003e\n   \u003cp\u003eLorem ipsum dolor sit amet, consectetur adipisicing elit.\u003c/p\u003e\n\u003c% include footer %\u003e\n```\n\nThe rendered HTML will look like this:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003ctitle\u003eSome Page\u003c/title\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003cmeta name=\"description\" content=\"This is some page\"\u003e\n  \u003cmeta name=\"author\" content=\"Timo Mämecke\"\u003e\n  \u003cscript src=\"/static/js/script1.js\" async=\"async\"\u003e\u003c/script\u003e\n  \u003clink href=\"/static/css/style.css\"\u003e\n  \u003clink href=\"/static/css/print.css\" media=\"print\"\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003ch1\u003eLorem ipsum\u003c/h1\u003e\n  \u003cp\u003eLorem ipsum dolor sit amet, consectetur adipisicing elit.\u003c/p\u003e\n  \u003cscript src=\"/static/js/script2.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Options\n\n* `cssPath` will be prepended to the filename of the CSS href\n* `jsPath` will be prepended to the filename of the script src\n* `urlArgs` are extra query string arguments appended to relative path URLs\n\nThe above configuration is ignored if absolute url is provided. eg:\n\n```js\naddScript('footer', 'https://cdnjs.cloudflare.com/ajax/libs/require.min.js')\n```\n\nOR\n\n```js\naddScript('footer', '//cdnjs.cloudflare.com/ajax/libs/require.min.js')\n```\n\nOR\n\n```js\naddScript('footer', 'http//cdnjs.cloudflare.com/ajax/libs/equire.min.js')\n```\n\nThen the original url is used and for example in the second case when `scripts('footer')`\nis called, no matter what configuration is used, it will result to:\n\n```html\n\u003cscript src=\"//cdnjs.cloudflare.com/ajax/libs/require.min.js\"\u003e\u003c/script\u003e\n```\n\n## Methods\n\nYou can use these methods in your template.\n\n**setTitle()**  \nSets the title of the page\n\n**addHead(htmlString)**  \nAdds a String of HTML.  \n* *htmlString* *(required)* is a line of text/html.\n\n**addStyle(file, attributes)**  \nAdds a Stylesheet `\u003clink\u003e`.  \n* *file* *(required)* is the filename of the CSS file.\n* *attributes* *(optional)* is a key-value object of HTML Attributes.\n\n**addScript(place, file, attributes)**  \nAdds a JavaScript `\u003cscript\u003e`.  \n* *place* *(required)* can be `header` or `footer`.  \n* *file* *(required)* is the filename of the JavaScript file.\n* *attributes* *(optional)* is a key-value object of HTML Attributes.\n\n**title()**  \nReturns the specified title.\n\n**head()**  \nReturns the specified HTML.\n\n**styles()**  \nReturns the specified Style Sources.\n\n**scripts(place)**  \nReturns the specified Script Sources.\n* *place* *(required)* can be `header` or `footer`.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Timo Mämecke\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimomeh%2Fejs-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimomeh%2Fejs-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimomeh%2Fejs-helper/lists"}