Skip to content

Instantly share code, notes, and snippets.

@dethe
Created September 30, 2011 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dethe/1252291 to your computer and use it in GitHub Desktop.
Save dethe/1252291 to your computer and use it in GitHub Desktop.
/**
* Additional content section / block functions for body.
*/
var rootpath = process.cwd() + '/',
path = require('path'),
calipso = require(path.join(rootpath, 'lib/calipso'));
exports = module.exports = function(req, options, callback) {
/**
* Get additional content for blocks in the template
*/
calipso.lib.step(
function getContentList() {
var alias = options.getPageId.split('.')[0];
options.getContentList({alias:alias}, {req:req}, this.parallel());
},
function done(err, contentlist) {
var content = contentlist.contents[0].toObject();
callback(err,{
project:content.content,
summary:content.summary,
equipment:content.equipment,
awards:content.awards
});
}
);
};
@cliftonc
Copy link

Does the getContent helper not work for you? It should take the alias as the first param, and return just the one object that matches (e.g. https://github.com/cliftonc/calipso/blob/master/themes/core/cleanslate/templates/home/body.js).

getContentList expects you to pass it a set of options that include a Mongoose query, so that it can select a set of content to display in a list or a section of a page - typically you use the getContentList for a landing page, then getContent to retrieve a specific piece of content.

We still need to add a feature that lets you change the default module renderer for a content type, so you can avoid what you are doing above and just use the 'normal' way, but you can over-ride the content module template (see calipso-site-theme again - it over-rides the login.html template in the user module) you can do this to over-ride the show.html template in the content module?

This is very good feedback, as this whole area clearly needs to be more intuitive and I need to complete these sections of the docs on the wiki. Are you using the main branch or devel?

Clifton

@dethe
Copy link
Author

dethe commented Sep 30, 2011 via email

@cliftonc
Copy link

Devel is quite stable, and has a lot of improvements - I think if you are going to be digging around as much as you are, it is probably best to use that.

Really happy to help, this is fantastic feedback as it gives me a different perspective on the way it is put together, and highlights some glaring weaknesses in the approach that need to either be explained better or (ideally) just fixed so they are simpler and more intuitive.

re. getContent - you're 100% right - it just returns the content property, not the content object itself. We need a new helper that is getContentObject, or refactor getContent to return the object and I will just change all existing use of it (0.3.0 is a breaking release anyway so I may do this to make it more consistent).

@cliftonc
Copy link

p.s. if you switch to github, you can run it straight from a clone, but you need to:

 npm install -d

and if you want to use the calipso cmd line, you need to use it like this:

./bin/calipso -s modules download cliftonc/calipso-elastic

You need to locally reference it, and the -s is to indicate that it is running from the source rather than a site install.

For module and theme development, I typically create a custom folder inside modules & themes, and then just git clone the other modules/themes from their repositories into there - this means you can work on the modules and themes separately but still run it all as one site - hth.

The devel branch has all the non-core modules removed.

Clifton

@dethe
Copy link
Author

dethe commented Sep 30, 2011 via email

@dethe
Copy link
Author

dethe commented Sep 30, 2011 via email

@cliftonc
Copy link

Yes - fork and work from that, you'll get used to github, once you submit a few pull requests and see how much easier it makes review etc. you'll be hooked.

I've just committed some changes to devel that sort of solve your problem in the short term, but not fix the longer term over-ride of content templates by content type (needs work!).

  • New helper: getParams() -> returns all the module params gathered during routing stage.

  • Changes: getContent changes ->

    options.getContent(req, "welcome-text", this.parallel()); => Will return the content property of matching content as before.
    options.getContent(req, {alias:"welcome-text",property:"content"}, this.parallel()); => Will do same as above.
    options.getContent(req, {alias:"welcome-text",property:"title"}, this.parallel()); => Will return the title property of matching content.
    options.getContent(req, {alias:"welcome-text"}, this.parallel()); => Will return the content object itself (as you don't specify a property).

Let me know if this helps.

Clifton

@jackygrahamez
Copy link

Hi Clifton, maybe I'm not following this right. I've been testing the Calipso code base for two days now. First with the NPM package. Now with the source code using the devel branch. I forked it and cloned my fork making sure to switch to the devel branch and then running the node app.js from the source directory. Now I'm trying to figure out how to use these custom fields from the content type custom fields tab. I looked at this thread

cliftonc/calipso#117
Maybe its all explained but I'm still not following. I took the gistfile1.txt and used it in the
themes/core/cleanslate/templates/home/body.js

restarted the server, created a content type home, then created content using type home and got this console error and server crash.

/Users/jgs/Projects/calipso/node_modules/mongoose/lib/utils.js:413
        throw err;
              ^
TypeError: Cannot call method 'toObject' of undefined
    at Function.done (/Users/jgs/Projects/calipso/themes/core/cleanslate/templates/home/body.js:20:43)
    at next (/Users/jgs/Projects/calipso/node_modules/step/lib/step.js:51:23)
    at /Users/jgs/Projects/calipso/node_modules/step/lib/step.js:83:14
    at Promise.<anonymous> (/Users/jgs/Projects/calipso/modules/core/content/content.js:938:9)
    at Promise.<anonymous> (/Users/jgs/Projects/calipso/node_modules/mongoose/lib/promise.js:120:8)
    at Promise.EventEmitter.emit (events.js:95:17)
    at Promise.emit (/Users/jgs/Projects/calipso/node_modules/mongoose/lib/promise.js:59:38)
    at Promise.complete (/Users/jgs/Projects/calipso/node_modules/mongoose/lib/promise.js:70:20)
    at cb (/Users/jgs/Projects/calipso/node_modules/mongoose/lib/query.js:918:32)
    at /Users/jgs/Projects/calipso/node_modules/mongoose/lib/utils.js:408:16

What I'm trying to figure out is if I can create a template with custom fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment