alecritson / Placid-Statamic

Consume REST services in your templates
MIT License
54 stars 1 forks source link

Scoping out a response without a root variable #5

Closed kidqueb closed 9 years ago

kidqueb commented 9 years ago

Hey there,

I'm dealing with an api delivering a structure like [ { property: 1 }, { property: 2 }, { property: 3 } ] that is preventing me from me being able to scope out the templates and access each one.

When I get a single record {{ property }} works fine, but when I get multiple I'm unable to access them.

Any ideas how I can achieve this?

Thanks, Nick

edit: https://docs.simplyrets.com/api/index.html#!/default/get_properties - this is the actual api im dealing with

alecritson commented 9 years ago

Hey @nmquebb

Thanks for pointing this out, there was a bit of a bug going on which meant if your response was an array, you couldn't loop over it.

I just pushed a new version which fixes this issue, now when the api returns a response and it is an array, it gets cast to a response variable which you can then loop over. Something like:

{{ placid handle="simplyrets" }}
   {{ response }}
        {{ property.roof }}
   {{ /response }}
{{ /placid }}

So If you download 1.0.2 and update placid this should work for you :+1: but if not, just reopen and we can take a look.

kidqueb commented 9 years ago

Perfect! I actually tried hacking together a fix too by just adding return array("properties" => $result); to line 192 haha. Shows how great I am with php.

Thanks for the quick fix. I'll upgrade and let you know how it works out.