Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Dealing with responses

alecritson edited this page Feb 13, 2016 · 1 revision

When you make a request, you are getting an instance of Placid_ResponseVariable back, this has a few helpers for you to use in your templates to make things easier.

Previously if something went wrong when making a request you would get nothing back, now this isn't the case, you will always get back what the API returns, you just have a different way to handle this.

{# returns `Placid_ResponseVariable` #}
{% set response = craft.placid.request('someApi') %}

{# Returns the response status code so `200` `404` `500` etc %}
{{ response.status }}

{# If you are expecting the data to be an array you can limit the amount of items within that like.. #}
{% set items = response.limit(5) %}

{# Then you can loop over the data like #}
{% for item in items.data %}
	{{ item.text }}
{% endfor %}