In the couchDB guide, Managing Design Documents, they state that
The _attachments directory contains files that are saved to the Sofa design document as binary attachments. CouchDB serves attachments directly (instead of including them in a JSON wrapper), so this is where we store JavaScript, CSS, and HTML files that the browser will access directly.
then further down they create a separate folder to store their templates, outside the _attachments folder. This is something that’s been puzzling me for a while now. They only way I’ve been able to include templates in my show functions is if they reside outside the _attachments folder.
Can I place my templates in the _attachments folder, or should they be placed outside the _attachments folder?
If I can/should place them inside the _attachments folder, how can I call them in my show functions?
If you want to render the templates server-side (
_showand_listfunctions) they must not be in _attachments because show and list functions do not have access to attachments. In these functions, the variablethisis a Javascript object, copied from the design document.this.templates.foowould come from thetemplates/foo.htmlfile in your project.If you want to render the templates client (browser) side, they may be in attachments, or in the design document. It depends what works better for you. With templates stored in attachments, you can fetch them directly, and use them on the client; you can simply link to it in your app or web page. You can also leave the templates in the design document and let the client fetch that whole document. Then, the client can use whichever templates it wants from the ddoc.