I need to be able to do pass the entry_id of the page being viewed into a json file to build a query.

I currently have a page setup that has a Playa field. I need to have a JSON file that will get the IDs of all of the Playa children so that I can pass those values to a map on the same page.

In the page, I have the following;

{exp:stash:set_list name="trail" parse_tags="yes" parse_depth="3"}  
    {exp:channel:entries channel="{channel}" status="open" limit="1" require_entry="yes"}



{exp:stash:get_list name="trail"}

    <h2>About the {trail_title}</h2>


<div class="mapwithborders">
    <div class="listing_map" data-api-url="trail-json"></div>

My 'trail-json.js' template has the following (but as you can see there is a hardcoded parent_entry_id;

{exp:query sql="SELECT child_entry_id AS entry_ids FROM exp_playa_relationships WHERE parent_entry_id = 2422"}
        "entry_id": "{entry_id}",
        "title": "{title}",
        "latitude": "{thingtodo_latitude}",
        "longitude": "{thingtodo_longitude}"

I would be grateful if someone could point me in the right direction to replace the hard-coded parent_entry_id.

Thank you.


1 Answer 1


One easy way to solve this is to just use a segment variable. You can use segment_2 to hold whatever value you want to use for your query. So assuming you wanted to find data for the parent entry #2422, you'd load your JSON template with a URL of /trail-json/2422.

In your page template where you're setting the URL for your JSON you'd do:

<div class="listing_map" data-api-url="trail-json/2422"></div>

(Replace "2422" with a variable as appropriate, if I understand your setup it would be {entry_id}).

Then in your trail-json.js template where have have hard-coded the parent_entry_id in your query you would instead do:

WHERE parent_entry_id = {segment_2}

Important note: the Query module isn't safe to use with segment variables. So you should switch to using the Active Record plugin instead of the Query module if you decide to use this approach.

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.