An open API service indexing awesome lists of open source software.

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

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}


```