Where should you store templates in your kuchapp?

In the couchDB Project Management guide , they state that

The _attachments directory contains files that are saved as binary attachments in the sofa design document. CouchDB directly inserts applications (instead of including them in the JSON shell), so here we store JavaScript, CSS and HTML files that the browser will access directly.

then further down they create a separate folder for storing their templates, outside the _attachments folder. This is what puzzled me for a while. They only mean that I could include templates in my show functions if they are outside the _attachments folder.

Can I place my templates in the _attachments folder or place them outside the _attachments folder?

If I can / should put them in the _attachments folder, how can I call them in my show functions?

+3
source share
2 answers

If you want to display the server-side functions of the templates ( _showand _list), they should not be in _attachments, because the show and list functions do not have access to attachments. In these functions, the variable thisis a Javascript object copied from the project document. this.templates.foowill be from a file templates/foo.htmlin your project.

(), . , . , , ; -. . ddoc.

+2

, _attachments , .

Couchapp script .

mustache . -:

Mustache.to_html(ddoc.templates.index, stash, ddoc.templates.partials, List.send);

, CouchDB API .

, , , .

Javascript .

+2

All Articles