1

I'm getting a strange issue when trying to display pagination inline. It appears that when their is no pagination to display, the {paginate} will echo out:

pagination_marker

I'm trying to display pagination in a json output format, this is what my entry tag looks like:

[
    {
        "category": {exp:query sql="SELECT cat_name FROM exp_categories WHERE 
cat_url_title = '{segment_4}'"}{exp:jsonencodetagpair}{cat_name}{/exp:jsonencodetagpair}{no_results}{redirect="404"}{/no_results}{/exp:query},
        "reviews": [{exp:channel:entries channel="reviews" category_url_title="{segment_4}" paginate="inline" status="open" limit="5" orderby="date" sort="desc" backspace="0" disable="categories|category_fields|member_data"}
            {   
                "id": {entry_id},
                "snippet":{exp:jsonencodetagpair}{review_snippet}{/exp:jsonencodetagpair},
                "slug": "deeplink/{entry_id}",
                "firstName": {exp:jsonencodetagpair}{review_first_name}{/exp:jsonencodetagpair},
                "lastName": {exp:jsonencodetagpair}{review_last_name}{/exp:jsonencodetagpair},
                "image": "{if '{review_reviewer_photo}' != ""}{global:site_url}{review_reviewer_photo}{/if}",
                "date":{exp:jsonencodetagpair}{entry_date format='%Y-%m-%dT%H:%i:%sZ'}{/exp:jsonencodetagpair}{if count != total_results}

            },{if:else}

            }
        ],
        "pagination": [{paginate}
            {
                "previous": {exp:jsonencodetagpair}{if previous_page}{auto_path}{/if}{/exp:jsonencodetagpair},
                "next": {exp:jsonencodetagpair}{if next_page}{auto_path}{/if}{/exp:jsonencodetagpair}
            }{/paginate}
        ]{/if}{no_results}],"pagination":[]{/no_results}{/exp:channel:entries}
    }
]

Now, since it has to be in a json format, I don't want my pagination to be within the array of reviews. This works perfectly when their are multiple pages to be displayed, but when their is only 1 or 2 reviews and no pagination needed, pagination_marker is then displayed.

Here is what the json looks like when it's working correctly:

[
    {
        "category": "Cosmetic Dentistry",
        "reviews": [
            {
                "id": 886,
                "snippet": "",
                "slug": "deeplink/886",
                "firstName": "test",
                "lastName": "test",
                "image": "",
                "date": "2013-07-31T12:37:00Z"
            },
            {
                "id": 883,
                "snippet": "",
                "slug": "deeplink/883",
                "firstName": "",
                "lastName": "",
                "image": "",
                "date": "2013-07-31T12:25:00Z"
            },
            {
                "id": 882,
                "snippet": "",
                "slug": "deeplink/882",
                "firstName": "James",
                "lastName": "Lukensow",
                "image": "",
                "date": "2013-07-31T12:22:00Z"
            },
            {
                "id": 881,
                "snippet": "",
                "slug": "deeplink/881",
                "firstName": "James",
                "lastName": "",
                "image": "",
                "date": "2013-07-31T12:19:00Z"
            },
            {
                "id": 880,
                "snippet": "",
                "slug": "deeplink/880",
                "firstName": "",
                "lastName": "",
                "image": "",
                "date": "2013-07-31T12:18:00Z"
            }
        ],
        "pagination": [
            {
                "previous": "",
                "next": "http://local.cds.test.com/v1/reviews/category/cosmetic-dentistry/P5"
            }
        ]
    }
]

This is what it looks like when it does not work:

[
    {
        "category": "Dentures",
        "reviews": [
            {
                "id": 879,
                "snippet": "",
                "slug": "deeplink/879",
                "firstName": "",
                "lastName": "",
                "image": "",
                "date": "2013-07-31T12:16:00Z"
            }
        ],
        "pagination": [
            {
                pagination_marker
            }
        ]
    }
]
1

The pagination link generator is pretty whacky, because the parser grabs the code in your template and then may move it, depending on whether you have paginate set to bottom or top.

This is probably an example of the EE parser not working in a strictly top-to-bottom manner, and catching us off-guard since we want the parser to follow the sequence of the code.

So, as an easy step, trying adding paginate="bottom" to your exp:channel_entries tag.

If that doesn't solve it, try taking the pagination code block all the way outside of the conditional {if count != total_results}. I can't think of exactly how that'd work in the JSON, but maybe this can work.

If those approaches don't work, then you need to think about having the pagination go into a placeholder variable that you can then put in the right place later. You might need PHP to do this, or one of the "jumper" add-ons like NSM Transplant might do the trick.

These examples of How to Use Stash for Pagination and Capturing Pagination might be helpful, too.

Also, the EE parser sometimes is not happy with lots of curly brackets and quotes on the page. I think this may have something to do with why you're seeing the pagination_marker placeholder rather than some other mess.

| improve this answer | |
  • Thanks, I've tried changing paginate="bottom". but then, that breaks the json layout. What I did to get a fix, was use a plugin called absolute_total_results. Then, I set my limit to 10, and do a check to see if absolute_total_results is greater than 10, display the pagination, if not, just display and empty array. Seems to get the job done. I know it's not the preferred way... – Whnunlife Aug 16 '13 at 16:56

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.