0

I have apostrophe blog running on the server and under the lib/modules/apostrophe-blog-pages/views folder I have two templates index.html and show.html. And I have added a new template popular.html. Want I am trying to do it for the third template I want to restrict the value to 10 blog posts or articles. Where are in all other cases show all articles. I was able trace the code back to the apostrophe pieces pages file on line 42 where if no value is passed the value is default to 10. https://github.com/punkave/apostrophe/blob/master/lib/modules/apostrophe-pieces-pages/index.js

depending on the page now I want to change that value from 10 to 100 or back to 10. I code that I have under ./lib/modules/apostrophe-blog-pages/index.js is

module.exports = {
    construct: function (self, options) {
        self.pageBeforeSend = function (req, callback) {
            function setPerPageValue() {
                return new Promise(function (resolve, reject) {
                    if(req.originalUrl.indexOf("popular") !== -1) {
                        self.options.perPage = 10;
                    } else {
                        self.options.perPage = 100;
                    }
                    console.log("after",self.options.perPage);
                    resolve(req);
                });
            }

            Promise.all([setPerPageValue()]).then(function (results) {
                // All promises were resolved
                return callback(null);
            })
            .catch(function (error) {
                // One or more promises was rejected
                return callback(error);
            });
        };
    },
}

but the value always remains the same. For some reason the passed value once set is not changing? Any help will be appreciated.

Parik Tiwari
  • 1,525
  • 1
  • 12
  • 19
  • Hi Parik, sorry I didn't spot this one sooner! I am scratching my head here because I don't have quite enough information. I can't see how you are implementing the popular page in the first place based on this. By default only the index page would try to fetch multiple pieces at all. I also don't know what constitutes popularity for you. But, you should look at overriding `dispatchAll` and adding a new method for your `popular` page, which could start by copying and simplifying the logic for the `indexPage` method to meet your needs. – Tom Boutell Mar 01 '17 at 15:18
  • Thank for the response Tom, we ended up adding a new field in the database called "count" and the value is incremented by one every time a user (unique userid) with a unique session id (generated by apos) access the page. And we basically show only (top) 10 results/articles on the blog pages template using if condition from mozilla nunjucks template engine. – Parik Tiwari Mar 01 '17 at 19:04

0 Answers0