Add basic CMS capabilities

to your Swig based views.

Overview

Sometimes, when you're done with your new and shiny Swig based app, your client wants to edit some content without paying you big buck$ to do it.

Simply sprinkle your Swig templates with {% cms 'myContentId' %} sections and you're done!

Features

Besides super easy and unobtrusive configuration Swig Tiny-CMS offers:

  • Support for Markdown content sections.
  • File-based persistence.
  • Works with Express 3.x and 4.x
  • Works on Node.js clusters.
  • WYSIWYG Markdown editor.

Usage

New tag 'cms' will be registered with your Swig template engine. ContentId string as a parameter is required:

{% cms 'contentId' %}

After adding this tag, editable content section will be available to your authorized users.

Content will be saved in a file with contentId.md name.

The same content identifiers can be used if you would like to reuse content sections.

Credits

This module would not be possible without these awesome dependencies:

Installation

npm install swig-tiny-cms --save

Configuration

Require Swig CMS

var swigCms = require('swig-tiny-cms');

After typical Express and Swig configuration, provide a way for Swig Tiny-CMS to know when user is authorized to edit content via middleware.

app.use(function(req, res, next){
  swigCms.isAdmin(req.isAuthenticated());
  next();
});

Declare Swig Tiny-CMS options:

var options = {

  //content directory is required
  //should be shared directory when used in cluster
  contentDirectory: __dirname + '/content/',

  //optional array of custom CSS files to be used in editor
  css: ['/css/custom.css'],

  //optional marked.js options
  //more info: https://github.com/chjj/marked
  markedOptions: { breaks: true }

};

Initialize Swig CMS

swigCms.initialize(swig, app, options);
Fork me on GitHub