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 🙂
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!
@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>
Ajlan
4
Fubar
2
Super User 2025 Season 1
CBDEV
2