Closed paul-frost closed 8 years ago
Hey @paul-frost
Currently Placid just returns whatever array is returned from the API your are querying. So you would need to pass a limit
value as the query string (assuming the API supports it)
Something like,
{% set events = craft.placid.request('EventsFeed', {
query: {
limit: 5
}
}) %}
This translates to http://yourapi.com/somefeed?limit=5
for example.
Thanks Alec, but the API doesn't support that. So is my IF loop the most efficient way to set a limit?
Hey @paul-frost
I actually just pushed an update which includes a way on how to resolve this for you, if you update to 1.7.112
you should be able to do:
{% set events = craft.placid.request('EventsFeed').limit(5) %}
{% for event in events.data %}
{{ event.title }}
{% endfor %}
Note the use of the .data
part, this is new in the latest version.
This is providing that the response is an array.
Thanks for that Alec, I appreciate it. Works perfectly.
I couldn't work out an easy way to restrict it to only getting or showing only the last 5 items from a feed. I had expected the following to work from looking at other code examples around:
{% set events = craft.placid.request('EventsFeed').limit(5) %}
I'm new to craft, so the only way I managed it was by wrapping the output in an iF loop in the template:{% if loop.index <= 5 %} display t items {% endif %}
Is there a better way? Could/should there be a limit option in the settings panel?