<p>Thanks for giving Placid a try, sucks you have had issues using it. I understand you're using Guzzle now, but for future reference I think I know what was going on.</p>
<h2>Caching</h2>
<p>In this case you would need to turn caching off for the Placid request, this is due to you needing a new request for each iteration, I will be looking to improve the caching in the near future to be more intelligent but in the meantime just setting <code>{ cache: false }</code> should fix this:</p>
<pre><code>{% for song in craft.entries.section('music') %}
  {% set params = { 'id' : song.itunesId } %}
   {% set lookup = craft.placid.get('itunesMusic', { params : params, cache: false } ) %}
   {% for track in lookup.results %}
    {{ track.trackName }}
  {% endfor %}
{% endfor %}
</code></pre>
<p>I've set up an example so you can <a href="http://alecritson.co.uk/documentation/placid/examples/itunes-track-info" rel="nofollow noreferrer">see it in action here</a></p>
<p>I hope that helps if you choose to use Placid again in the future!</p>

CC BY-SA 3.0
2014-10-20T15:37:57.533Z
Hey Alec, thanks for replying! I didn't even realize that! I realize I was hacking Placid a little differently than it's intended use as well. If I were better at PHP (which hopefully after digging into it more I will be), I'd love to help out in whatever way I could!
Spentacular
CC BY-SA 3.0
2014-10-21T07:41:12.070Z
No worries, it can sometimes be an easy oversight when developing! :) I think the way you are using Placid is fine though, the caching just needs updating so you don't hammer the API with requests on each page load, but that will come! If you ever do want to contribute, the project is on Github so just send a pull request, always welcome :)
Alec Ritson
CC BY-SA 3.0
2014-10-31T11:48:46.627Z
@Alec is there any reason not to use Craft's `cache` tag to cache the whole loop? Do you see any problems I might run into? Thanks for the plugin btw!!
carlcs
CC BY-SA 3.0
2014-10-31T12:11:49.797Z
Hey @carlcs, thanks for checking Placid out! There shouldn't be any issues using crafts `cache` tag, if you do get any issues i'd be interested to see why. I added caching to placid mainly just as a failsafe, if some people aren't in the habit of using the `cache` tag or they forget etc...it should at least minimise performance hits where it's being used :)
Alec Ritson
CC BY-SA 3.0
2014-10-20T12:02:34.717Z
2014-10-20T12:02:34.717Z
2020-06-17T08:56:27.903Z
Alec Ritson
<p>I am trying to use the <a href="http://alecritson.co.uk/projects/placid" rel="nofollow">Placid plugin</a> to retrieve track-names from an external service, and having problems. I have the following code:</p>

<pre><code>{% for song in craft.entries.section('music') %}
  {% set params = { 'id' : song.itunesId } %}
  {% set lookup = craft.placid.get('itunesMusic', { params : params } ) %}

  {% for track in lookup.results %}
    {{ track.trackName }}
  {% endfor %}
{% endfor %}
</code></pre>

<p>The values of <code>song.itunesId</code> and <code>params</code> seem to be set correctly, however <code>lookup.results</code> is returning the same <code>track.trackName</code> on each iteration of the loop.</p>

CC BY-SA 3.0
2014-10-19T13:19:38.613Z
Hey Douglas. I'm using a plugin called [Placid](http://alecritson.co.uk/projects/placid), and it is using that method. My `loop.index` increments, and so does my `song.itunesId` when I set them up like `{{ song.itunesId }}`, but inside the loop it's not resetting the value of params to the new `song.itunesId`.
Spentacular
CC BY-SA 3.0
2014-10-19T17:59:38.110Z
@DouglasMcDonald ahh, that way didn't work either. I'm getting output fine from both loops, the problem is `{{ track.trackName }}` only displays the first `song` track name (in the case the track name is Bless Your Name, so it outputs Bless Your Name twice), but if I put `{{ song.itunesId }}` in the first loop, it iterates over both values. Is there any way to make sure both of the `set` values reset for each iteration of the loop, instead of "sticking"?
Spentacular
CC BY-SA 3.0
2014-10-19T18:27:28.023Z
The set params value should iterate fine. Have you tried printing {{ params['id'] }} to test?
Douglas McDonald
CC BY-SA 3.0
2014-10-19T18:42:57.347Z
Hmmm, now I'm lost, because that does work. Now I have no clue what to do since that `placid.get` method isn't taking the new variable each time in the loop. Basically, I'm just trying to get the id I added in an entry and put it on the end of the iTunes Search api, i.e. https://itunes.apple.com/lookup?id=`721273648`, where the last number is different. That is weird that it doesn't work.
Spentacular
CC BY-SA 3.0
2014-10-19T19:28:18.263Z
That is weird. Should work. I hope you don't mind, I edited the question and deleted my comments which no longer applied.
Douglas McDonald
CC BY-SA 3.0
2014-10-19T19:59:25.783Z
Nope, not at all. I ended up switching and using [Guzzle](https://github.com/davist11/craft-guzzle) and it ended up working just fine! Thanks for your help!
Spentacular
CC BY-SA 3.0
2014-10-19T20:31:15.820Z
Great! I'm glad you worked out a solution. Must be apple then? Strange. When your done, you might want to post an answer and delete any extraneous comments that don't apply anymore.
Douglas McDonald
<templating><plugins>
Variables not iterating in for loop
# Variables not iterating in for loop

(Asked by: username_0 on 2014-10-19)

I am trying to use the Placid plugin to retrieve track-names from an external service, and having problems. I have the following code:
{% for song in craft.entries.section('music') %}
  {% set params = { 'id' : song.itunesId } %}
  {% set lookup = craft.placid.get('itunesMusic', { params : params } ) %}

  {% for track in lookup.results %}
    {{ track.trackName }}
  {% endfor %}
{% endfor %}

The values of song.itunesId and params seem to be set correctly, however lookup.results is returning the same track.trackName on each iteration of the loop.

**Tags:** templating, plugins
> **Comments:**
> **username_0**: Hey Douglas. I'm using a plugin called [Placid](http://alecritson.co.uk/projects/placid), and it is using that method. My `loop.index` increments, and so does my `song.itunesId` when I set them up like `{{ song.itunesId }}`, but inside the loop it's not resetting the value of params to the new `song.itunesId`.  
> **username_0**: @DouglasMcDonald ahh, that way didn't work either. I'm getting output fine from both loops, the problem is `{{ track.trackName }}` only displays the first `song` track name (in the case the track name is Bless Your Name, so it outputs Bless Your Name twice), but if I put `{{ song.itunesId }}` in the first loop, it iterates over both values. Is there any way to make sure both of the `set` values reset for each iteration of the loop, instead of "sticking"?  
> **username_1**: The set params value should iterate fine. Have you tried printing {{ params['id'] }} to test?  
> **username_0**: Hmmm, now I'm lost, because that does work. Now I have no clue what to do since that `placid.get` method isn't taking the new variable each time in the loop. Basically, I'm just trying to get the id I added in an entry and put it on the end of the iTunes Search api, i.e. https://itunes.apple.com/lookup?id=`721273648`, where the last number is different. That is weird that it doesn't work.  
> **username_1**: That is weird. Should work. I hope you don't mind, I edited the question and deleted my comments which no longer applied.  
> **username_0**: Nope, not at all. I ended up switching and using [Guzzle](https://github.com/davist11/craft-guzzle) and it ended up working just fine! Thanks for your help!  
> **username_1**: Great! I'm glad you worked out a solution. Must be apple then? Strange. When your done, you might want to post an answer and delete any extraneous comments that don't apply anymore.  

---

## 1 answers

### Answer by username_2 on 2014-10-20. Score: 2 | Accepted answer

Thanks for giving Placid a try, sucks you have had issues using it. I understand you're using Guzzle now, but for future reference I think I know what was going on.
Caching
In this case you would need to turn caching off for the Placid request, this is due to you needing a new request for each iteration, I will be looking to improve the caching in the near future to be more intelligent but in the meantime just setting { cache: false } should fix this:
{% for song in craft.entries.section('music') %}
  {% set params = { 'id' : song.itunesId } %}
   {% set lookup = craft.placid.get('itunesMusic', { params : params, cache: false } ) %}
   {% for track in lookup.results %}
    {{ track.trackName }}
  {% endfor %}
{% endfor %}

I've set up an example so you can see it in action here
I hope that helps if you choose to use Placid again in the future!

> **Comments:**
> **username_0**: Hey Alec, thanks for replying! I didn't even realize that! I realize I was hacking Placid a little differently than it's intended use as well. If I were better at PHP (which hopefully after digging into it more I will be), I'd love to help out in whatever way I could!  
> **username_2**: No worries, it can sometimes be an easy oversight when developing! :) I think the way you are using Placid is fine though, the caching just needs updating so you don't hammer the API with requests on each page load, but that will come! If you ever do want to contribute, the project is on Github so just send a pull request, always welcome :)  
> **username_3**: @Alec is there any reason not to use Craft's `cache` tag to cache the whole loop? Do you see any problems I might run into? Thanks for the plugin btw!!  
> **username_2**: Hey @carlcs, thanks for checking Placid out! There shouldn't be any issues using crafts `cache` tag, if you do get any issues i'd be interested to see why. I added caching to placid mainly just as a failsafe, if some people aren't in the habit of using the `cache` tag or they forget etc...it should at least minimise performance hits where it's being used :)  

---

