Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Customize & Extend
Answered

Fetch XML pagination

(0) ShareShare
ReportReport
Posted on by 17

Hey guys,

 

So I've been struggling with the following issue in the last days.

 

I have a huge photo library that I want to display to users (+200 photos). Those photos are stored in Dataverse in a base64 code. They are not huge in size, only about 200-300kb.

 

I am using then a fetch xml to get the photos and display them in the portal. The issue I'm having is that the portal can't display all of them (because of the combined size, I guess) and it stops at some point.

 

I tried paginating them using this article and it works fine for the first page, but I'm struggling with navigating to the second page.

If I do it manually, like this; it works.

 

<a href="?page=2">Next page</a>

 

 

But if I try to set the page variable to plus 1, it doesn't do that. 

 

<a href="?page={% assign page = page | plus: 1 %}">Next</a>

 

And it shows this error: Liquid error: Input string was not in a correct format. 

 

This is the whole code, maybe it helps. 

 

{% assign pagingCookie = request.params['paging-cookie'] %}
{% if pagingCookie %}
 {% assign pagingCookie = ' paging-cookie="{{ pagingCookie }}"' | liquid %}
{% endif %}
{% fetchxml bag_query %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" {{ pagingCookie }} page="{{ request.params['page'] | default:1 }}" count="10">
 <entity name="bg_bag_detail">
 <attribute name="bagdescription" />
 <attribute name="autoid" />
 <order attribute="autoid" descending="false" />
 <filter type="and">
 <condition attribute="statecode" operator="eq" value="0" />
 </filter>
 </entity>
</fetch>
{% endfetchxml %}

{
 "morerecords": {{ bag_query.results.more_records }},
 "paging-cookie": "{{ bag_query.results.paging_cookie }}",
 "paging-cookie-encoded": "{{ bag_query.results.paging_cookie | escape | url_escape }}",
 "page": {{ request.params['page'] | default: 0 }},
 "results": [
 {% for item in bag_query.results.entities %}
 {
 "bag_description":{{ item.bagdescription }}
 }
 {% unless forloop.last %},
 {% endunless %}
 {% endfor %}
 ]
 }



<a href="?page={% assign page = page | plus: 1 %}">Next</a>

 

 

Basically I'm stuck and I can't find a way to go to the next page. 

Please help 🙂 

Categories:
  • Verified answer
    SimperingLemon1 Profile Picture
    17 on at
    Re: Fetch XML pagination

    Hi Fubar,

     

    Thank you for your reply.

     

    This bit has actually pointed me in the right direction.

     

    I don't really know why, but it seems like all the variables are stored as strings and I wasn't able to do any math on them. I ended up using the following code to convert them to a integer.

    {% assign page = page | integer | plus : 0 %}

    After that I was able to keep adding to this and navigating to further pages.

     

    I'll attach the code below as a reference.

    {% if request.params.page == nil %} <!–– this bit is only for setting the first page to 1, and then adding a +1 to get to the second page --> 
     {% assign page = 1 %}
     {% assign page = page | integer | plus: 1 %}
     {% else %} <!-- this bit is for the next pages --> 
     {% assign page = request.params['page'] %}
     {% assign page = page | integer | plus : 0 %}
     {% assign page = page | integer | plus: 1 %}
    {% endif %}

    And then I'm using your suggestion for the hyperlink. 

    Works like a charm.

     

    Thanks again!

  • Verified answer
    Fubar Profile Picture
    7,964 Super User 2025 Season 1 on at
    Re: Fetch XML pagination

    @SimperingLemon1 wrote:

     

    But if I try to set the page variable to plus 1, it doesn't do that. 

     

     

    <a href="?page={% assign page = page | plus: 1 %}">Next</a>

     

     

    And it shows this error: Liquid error: Input string was not in a correct format. 

     


    Assign just assigns it does not output.  You need something like

     

    {% assign page = page | plus: 1 %}
    
    <a href="?page={{page}}">Next</a>

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 69 Super User 2025 Season 1

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 49 Most Valuable Professional

#3
Jon Unzueta Profile Picture

Jon Unzueta 43

Featured topics