3

Puzzle of the day: How does one load paginated entries on a different template?

Let's say in my homepage I'm loading the latest 5 entries and I would like to have pagination links below, however I want these to load on a different template. (in order to have less rings and bells than on the homepage)

I tried to use routes but it doesn't seem to be working, is this because the pagination works from the original template?

Here's what I tried for example.com where example.com/p2 is paginated:

'(?P<page>\d+)'     // page must be the answer, right?       nope...
'p(?P<number>\d+)'  // let's try combining 'p' and a number  nope...
'p\d+'              // how about with just the regex?        nope...
'(?P<page>)'        // also targets homepage so...           nope...

I also tried doing it in the CP with no results.

5

I don't know if there's a route way to handle this, but you could do a conditional on the craft.request method getPageNum() like so:

{% if craft.request.getPageNum == 1 %}
    <!-- Header for the home page -->
{% else %}
    <!-- Header for pagination pages -->
{% endif %}
  • Thanks for the suggestion! Although it feels a little hacky it does get the job done. – cballenar Aug 14 '14 at 4:42
  • Why do you think it's hacky, because you use one template for both situations? What about using this template for this expression only and only use it to include two separate files? – carlcs Aug 14 '14 at 5:48
  • @cballenar forgot the @ mention – carlcs Aug 14 '14 at 5:49
  • I think it was because what I was trying to do was hacky. I'm currently rethinking the way the homepage is structured. I'm realizing that the homepage may not need "pagination" at all but just a link to the rest of articles. i.e.: example.com/articles/p# – cballenar Aug 14 '14 at 14:26
  • P.S.: it erased the @ mention... I wonder if it does it automatically when replying to the last person that commented? – cballenar Aug 14 '14 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.