1

I'm using couchdb\couchapp to host a web application. I comes from Django, and with jinja2 I'm able to extend templates in two ways:

{% include "header.html" %}

or

{% extends "base.html" %} <<<---- preferred

I'm looking for a way to do the same with CouchDB, now I have header and footer code written in every single page and, obv, it doesn't look as best practice.

Thank you in advance.

Guido
  • 319
  • 2
  • 9
  • I managed it concatenating the templates 'header' 'body and 'footer' from a show function with a simple js. – Guido Jun 28 '14 at 09:08

1 Answers1

1

Couch db supports common js modules which means that you can export the mustache/or other templating library as a string and then require it in your show function. More explanation on this mail archive

If you want to use JavaScript on the server side, you'll need to store it as a property on your design doc. So in a "lib" folder (outside of _attachments) with the 'couchapp' it will get included like:

couchapp folder

_id file

|_ _attachments folder

|_ ...clientside media...

|_ lib folder

|_ mustache.js

<---->

{_id:"", _attachments: {...}, lib:{mustache:""}}

Then you would use it in a _show/_list/_update function with var Mustache = require('lib/mustache'). When I do need a library both server and clientside with 'couchapp', I tend to symlink it so it appears in both _attachments and other properties.

hope this helps,

-natevw

Akshat Jiwan Sharma
  • 15,430
  • 13
  • 50
  • 60