I've got a frontend form which queries the openstates.org API to return a given set of data objects.

Those objects also exist in Craft as entries, and the API data includes a field that serves as a unique ID for the Craft entries - how can I pass those unique IDs back to the Craft template to retrieve the corresponding entries?

  • 3
    You could add them as query string to the URL. When rendering the page, you can tan check the query strign to see which ones you'd have to display...
    – mrsmn
    Commented Jul 26, 2017 at 5:57
  • Thanks, Michael - that worked perfectly. I wound up combining it with the sample code from this answer.
    – mierla
    Commented Jul 26, 2017 at 15:23
  • 1
    Perhaps add your working combination as answer? That way people in the future can directly see the answer.
    – mrsmn
    Commented Aug 1, 2017 at 13:24

1 Answer 1


Per Michael's suggestion above, with some help from this answer, I passed the results from the API call back to a craft template as query params, so it looked like this (simplified):

{% if craft.request.isAjax %}
    {% set myReps = craft.request.getParam('personId') %}
    {% set myIds = myReps | split(',') %}
    {% for myId in myIds %}
        {% set person = craft.entries.section('representatives').repId(myId).first() %}
    {% endfor %}
{% endif %}

and then output my info from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.