alecritson/Placid-Statamic

[V2] Can't get data out {{ response }} for JSON starting with arrays

Opened this issue · 3 comments

For an API not starting with an array this works:

{{ placid:request url="http://httpbin.org/get" cache="0" }}
  {{ if no_results }}
    <h1>No results</h1>
  {{ else }}
    <h1>Results</h1>
    <ul>
      <li>{{ url }}</li>
      <li>{{ origin }}</li>
    </ul>
  {{ /if }}
{{ /placid:request }}

But as per the docs for an API that returns and array I can't get any data out:

{{ placid:request url="http://jsonplaceholder.typicode.com/posts" cache="0" }}
  {{ if no_results }}
    <h1>No results</h1>
  {{ else }}
    <h1>Results</h1>
    {{ response }}
      <ul>
        <li>{{ id }}</li>
        <li>{{ title }}</li>
      </ul>
    {{ /response }}
  {{ /if }}
{{ /placid:request }}

Note that {{ if no_results }} is not triggered so data is returned.

Hey @netnak

Thanks for pointing this out, looks like v2 needs slightly different returns to get it to output for arrays, this should now be fixed if you download the latest.

Works great, thank you for the quick response.

FYI, even data that previously didn't need to be wrapped in the {{ response }} tag as per my first example now requires to be wrapped in it.

No worries.

Thanks for the heads up about the {{ response }} tag, this should now be fixed in 2.0.3