Skip to content

Instantly share code, notes, and snippets.

@rahularyan
Last active September 27, 2016 07:32
Show Gist options
  • Save rahularyan/5e78d3a3bd4209d331b1116f5cc9be06 to your computer and use it in GitHub Desktop.
Save rahularyan/5e78d3a3bd4209d331b1116f5cc9be06 to your computer and use it in GitHub Desktop.
/**=== Post Query ===**/
let args = {
termsQuery: {
...
},
dateQuery: {
..
},
metaQuery: {
..
},
...
}
let posts = postHelper.getPosts(args); // This will return PostQuery constructor
posts.fetchPosts().then(function(){
res.render('posts/index', {
title: 'Posts',
posts: posts
});
});
/** ===Action=== */
// Registering an action
hooks.doAction('savePost', post);
// adding an action
hooks.action('savePost', function(post){
// This action will be triggred right after saving a post
console.log(post.id());
});
/**
* =========Filter=========
*/
// Registering a filter
hooks.applyFilters('postTitle', title);
//adding a filter
hooks.filter('postTitle', function(title){
// This will filter post title and append site name
return title + ' - SiteName.com';
});
/**=== Register admin pages ===**/
function registerAdminPages(pages){
let newPages = [
{
id: 'posts',
title: 'Posts',
route: '/admin/posts',
icon: 'i-pin',
fn: wrap(controller.postsIndex),
submenu:[
{
id: 'new-post',
title: 'New Post',
route: '/admin/post/new',
icon: 'i-pin',
fn: wrap(controller.getNewPost)
}
]
}
];
return _.concat(pages, newPages);
}
hooks.filter('adminPages', registerAdminPages, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment