Skip to content

Instantly share code, notes, and snippets.

@Michael-Lazell
Created May 12, 2015 23:14
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 Michael-Lazell/f773026ca90d0e95bf4e to your computer and use it in GitHub Desktop.
Save Michael-Lazell/f773026ca90d0e95bf4e to your computer and use it in GitHub Desktop.
/**
* Returns the content with all of the reference related content
* @param {string} the content path or id.
* @param {object} the name of the reference and the new name that the actual content objects will have.
* @return {object} the content with all of its reference content objects.
*/
exports.content.getWithRefs = function(key, refs) {
/*Example object structure. Note this only works for single contents.
{
'image' : 'imageContent',
'department' : 'departmentContent'
}*/
if(exports.content.exists(key)){
var content = exports.content.get(key);
var data = content.data;
var ref;
for ( ref in refs ) {
if(refs.hasOwnProperty(ref)) {
data[refs[ref]] = exports.content.get(data[ref]);
}
}
return content;
}
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment