This example provides a proof of concept for simple EJS-based template rendering in ActionHero. Note that EJS is this author's favorite "simple" NodeJS template engine but it could easily be replaced with any other engine you wish.
- Copy
ejs.js
toinitializers/
. - Create a folder called
templates/
and copyleaderboard.js
there. - Copy the sample 'getLeaderboard.js' action to
actions/
.
Once you do this, start or restart your local ActionHero service. Assuming you started it on port 3000, the following two URLs should now work:
http://localhost:3000/?action=getLeaderboard http://localhost:3000/?action=getLeaderboard&format=html
If format is not specified as HTML, standard JSON (API-style) is returned to the client as you would expect. If format is set to html, a template is rendered with the same data.