Skip to content

Commit

Permalink
Fix data merging & add pagination block param
Browse files Browse the repository at this point in the history
refs #5993

- Don't merge the result set with the existing template data.
- If available, return `meta.pagination` as the second blockParam
  • Loading branch information
ErisDS committed Oct 23, 2015
1 parent 64d9ce4 commit 6ecc389
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/server/helpers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,24 @@ get = function get(context, options) {
apiOptions = parseOptions(this, apiOptions);

return apiMethod(apiOptions).then(function success(result) {
result = _.merge(self, result);
var blockParams;

// If no result is found, call the inverse or `{{else}}` function
if (_.isEmpty(result[context])) {
return options.inverse(self, {data: data});
}

// block params allows the theme developer to name the data using something like
// `{{#get "posts" as |result pagination|}}`
blockParams = [result[context]];
if (result.meta && result.meta.pagination) {
blockParams.push(result.meta.pagination);
}

// Call the main template function
return options.fn(result, {
data: data,
blockParams: [result[context]]
blockParams: blockParams
});
}).catch(function error(err) {
data.error = err.message;
Expand Down

0 comments on commit 6ecc389

Please sign in to comment.