Skip to content

Instantly share code, notes, and snippets.

@chrtze
Last active August 29, 2015 14:22
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 chrtze/4862d962c093f291ec32 to your computer and use it in GitHub Desktop.
Save chrtze/4862d962c093f291ec32 to your computer and use it in GitHub Desktop.
Ghost: Display All Tags
//insert at line 61 in: /core/server/controllers/frontend.js
function formatPageResponse(posts, page) {
// Delete email from author for frontend output
// TODO: do this on API level if no context is available
posts = _.each(posts, function (post) {
if (post.author) {
delete post.author.email;
}
return post;
});
return {
posts: posts,
pagination: page.meta.pagination,
all_tags: formatTags(posts)
};
}
function formatTags(posts) {
var check = [];
var tags = [];
posts.forEach(function(p,i) {
p.tags.forEach(function(t,j) {
if(check.indexOf(t.name) < 0) {
tags.push(t);
check.push(t.name);
}
});
});
return tags;
}
{{#foreach all_tags}}
<li><a href="{{url}}">{{name}}</a></li>
{{/foreach}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment