node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


Cheerio Template engine for Express


Express template engine, based on cheerio inspired by express-notemplate.

Allows the use of jQuery syntax in views of your application.

npm install cheerio-template

cd ./demo
npm install
node ./app.js

Enjoy in browser, http://localhost:3000

'use strict';
var application_root = __dirname,
        express = require('express'),
        path = require('path'),
        CheerioTemplate = require('cheerio-template');
var app = express();
// Config 
app.configure(function() {
    app.use(express.static(path.join(application_root, '/public')));
    app.set('views', path.join(application_root, '/views'));
    app.engine('html', CheerioTemplate.engine);
    app.set('view engine', 'html');
<div class="my-div"> </div>
<script type="text/javascript" cheerio-template>
    $('.my-div').html('New content for div');
<!DOCTYPE html>
        <script type="cheerio-template-block" block='content'></script> 
        <script type="cheerio-template-block" block='xtras'></script> 
<!-- Markup extends -->
<script type="cheerio-template-extends" extends='layout'></script>
<!-- Block Content -->
<div cheerio-template-block="content">
    <p>Content page</p>
<!-- Block xtras -->
<div cheerio-template-block="xtras">
    <p>Extra content page</p>
app.get('/route', function(req, res) {
    res.render('view', {
        title:'Other Page',
            name : 'Alex Rodin'
<div id="#title"></div>
<div id="#author-name"></div>
<script type="text/javascript" cheerio-template>
<div cheerio-template-mixin="formSelect">
    <div id="content"></div>
    <script type="text/javascript" mixin="formSelect">
        var formSelect = function(options, name, id, value, selectClass) {
            selectClass = selectClass ? selectClass : '';
            name = name ? name : '';
            id = id ? id : name;
            var select = $('<select />', {
                id: id,
                name: name,
                class: selectClass
            select.append('<option value="">...</option>');
            for (var i in options) {
                var option = options[i];
                var selected = (value && value === option.value) ? 'selected' : undefined;
                var $option = $('<option />');
                $option.attr('value', option.value);
                $option.attr('class', option.class);
                $option.attr('selected', selected);
            return $('#content').html();
<div id="my-select-container"></div>
<script type="text/javascript" cheerio-template>
            value: 2013,
            text: 'Year 2013',
            class: 'class-for-option'
            value: 2014,
            text: 'cup of world 2014',
            class: 'class-cup-of-world'
    ], 'name_for_form_select', 'select_id', 2013, 'select_class'));
<script type="cheerio-template-include" include='include/header'></script>
<script type="cheerio-template-include" include='include/mixins'></script>
<script type="cheerio-template-include" include='include/footer'></script>
<script type="cheerio-template-include" include='include/copy'></script>
<script type="text/javascript" cheerio-template>
    echo('<p>This text was inserted</p>');