https://github.com/robojones/express-marko
Express middleware for marko template engine
https://github.com/robojones/express-marko
express marko node nodejs npm
Last synced: 3 months ago
JSON representation
Express middleware for marko template engine
- Host: GitHub
- URL: https://github.com/robojones/express-marko
- Owner: robojones
- License: mit
- Created: 2017-02-27T17:23:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-05T11:36:39.000Z (over 9 years ago)
- Last Synced: 2025-03-22T22:01:45.605Z (over 1 year ago)
- Topics: express, marko, node, nodejs, npm
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-marko
## Installation
```
npm install express-marko --save
```
## Usage
### Example
```javascript
const app = require('express')()
const marko = require('express-marko')
// tell express-marko where your templates are (default: process.cwd())
app.set('views', 'views/')
// add the marko middleware to your app
app.use(marko)
app.get('/', (req, res, next) => {
// this will render the file views/home.marko
res.render('home')
})
app.listen(8080)
```
__Note:__ If you set `process.env.NODE_ENV` to `'development'`, your templates will not be cached.
## res.render()
See [res.render](http://expressjs.com/en/api.html#res.render) in the express API.
## Example - add locals
__Express:__
```javascript
app.get('/profile', (req, res, next) => {
res.render('profile', {
name: 'Alfons',
age: 24
})
})
```
__Template:__
```html
Profile of ${data.name}
Hi. I am ${data.name} and I am ${data.age} years old.
```
__Output:__
```html
Profile of Alfons
Hi. I am Alfons and I am 24 years old.
```
## Example - $global
```javascript
app.get('/example', (req, res, next) => {
res.global.name = 'Alfons'
res.render('example', {
$global: {
age: 24
},
color: 'blue'
})
})
```
You can access the name and age within you template:
```html
Hi ${out.global.name}
You are ${out.global.age}
You like the color ${data.color}
```