<![CDATA[ Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource - My Forums]]> https://forums.modx.com/thread/?thread=102608 <![CDATA[Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=3#dis-post-552852
I've got a getResources call returning data in JSON format - this culls its data from resources with content type JSON. The correct amount of items are being returned but the data (from TV's) is only being returned from the first resource.

What I'm trying to achieve is a JSON list for google map markers - this works fine outside of MODX in vanilla JS with the maps API so I'm attempting to transpose it into a MODX format. I don't really want to use an Extra for this for a number of reasons.

I've read up about this and think I'm doing it right ... https://forums.modx.com/thread/100338/using-snippet-and-getresources-in-external-javascript

Here's the getResources call, which is inside a <script> tag:
xyz javascript ... (all working) ...
...
var locations = [
	[[getResources? &parents=`26` &showHidden=`0` &hideContainers=`1` &tpl=`tpl.wrapper-GMapVars` &tplLast=`tpl.wrapper-GMapVars-Tail` &showHidden=`1` &includeTVs=`1` &processTVs=`1` &depth=`1` &limit=`20`]]
]


Here's the templates used in the GR call.
tpl.wrapper-GMapVars and tpl.wrapper-GMapVars-Tail are identical but 'GMapVars-Tail' omits trailing comma for correct JSON syntax, and both use a chunk for the TV's/JSON object properties:
{
lat: [[+tv.map-latitude]],
lng: [[+tv.map-longitude]],
info: '<div class="info_content">'+
'<h3>[[+tv.map-location]]</h3>'+
'<p>[[+tv.map-description]]</p>'+
'</div>'
},

This renders correctly within a <script> call, i.e. it renders 3 JSON objects from the 3 resources in id:26. However, the data in each of the 3 JSON objects is from the 1st resource only.

Can anyone see what's wrong here??? How can I get the data from the resources to render in their respective JSON objects?

Hope I've written this clearly, thanks in advance.]]>
powellian Jul 29, 2017, 11:51 AM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=3#dis-post-552852
<![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552988 donshakespeare Aug 03, 2017, 09:27 PM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552988 <![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552979
and both use a chunk for the TV's/JSON object

Ah, I see now. Sorry! Allways better to show us all your code. We are better in reading code, than reading words wink

I'm glad, this is solved!]]>
Bruno17 Aug 03, 2017, 02:55 PM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552979
<![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552978 Quote from: Bruno17 at Aug 03, 2017, 04:23 AM
you didn't say, that there is a chunk in your tpl.
In the opening post I put this:
tpl.wrapper-GMapVars and tpl.wrapper-GMapVars-Tail are identical but 'GMapVars-Tail' omits trailing comma for correct JSON syntax, and both use a chunk for the TV's/JSON object properties: ...

But I can see that this could easily be missed/misinterpreted, and whatsmore, Bruno your solution I wouldn't have got anyway wink
This is the accepted answer because it works! I've learnt through this, many thanks.]]>
powellian Aug 03, 2017, 01:59 PM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552978
<![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource (Best Answer)]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552948 Each modx-tag has to have a unique footprint (different properties) within one request.
If you call the same MODX - tag with the same footprint (same properties), for example a chunk, two or more times, the first one is cached for the whole request.
This is for speeding reasons, if you call the same snippet or chunk with the same properties more than once only the first one has to be processed. The next ones get the output from an internal cache.

The solution is simple. Call your chunk within the tpl like that:

[[$tplCodeblockGMapVarsLITE? &id=`[[+id]]`]]


Quote from: Bruno17 at Aug 01, 2017, 02:59 PM
Sounds like that isn't the issue, because the OP sees three items, but only with the same values for each item.
Maybe a strange placeholder-caching-issue?
]]>
Bruno17 Aug 03, 2017, 04:23 AM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552948
<![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552927
If you could have a peek in the manager that would be much appreciated. Can pm you details, that ok?

ok]]>
Bruno17 Aug 02, 2017, 01:31 PM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552927
<![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552925 Quote from: Bruno17 at Aug 02, 2017, 09:52 AM
without &tplLast, what happens then?
btw: you don't need this &tplLast at all, but you can have
&outputSeparator=`,`
Aha, 'tplLast' is a good tip, added it have correct json formatting - the problem remains though sad

I've added one more tv to the 'good' gR return block (location name) and it still works fine. Below is a straight copy of what's output in the page with the correct returns in italics. You can see the 3x json objects below that, each returning from the 1 resource:

Location 01 - 46.184570
Location 02 - 46.179147
Location 03 - 46.190244

{ lat: 46.184570, lng: 6.697508, info: '
Location 01
Spicy jalapeno bacon ipsum dolor amet burgdoggen beef beef ribs shankle, landjaeger kevin chicken leberkas corned beef t-bone ribeye swine bresaola. Pastrami shoulder hamburger picanha doner spare ribs chuck pig fatback cupim turkey turducken beef cow.

' },{ lat: 46.184570, lng: 6.697508, info: '
Location 01
Spicy jalapeno bacon ipsum dolor amet burgdoggen beef beef ribs shankle, landjaeger kevin chicken leberkas corned beef t-bone ribeye swine bresaola. Pastrami shoulder hamburger picanha doner spare ribs chuck pig fatback cupim turkey turducken beef cow.

' },{ lat: 46.184570, lng: 6.697508, info: '
Location 01
Spicy jalapeno bacon ipsum dolor amet burgdoggen beef beef ribs shankle, landjaeger kevin chicken leberkas corned beef t-bone ribeye swine bresaola. Pastrami shoulder hamburger picanha doner spare ribs chuck pig fatback cupim turkey turducken beef cow.

' }

If you could have a peek in the manager that would be much appreciated. Can pm you details, that ok?]]>
powellian Aug 02, 2017, 12:01 PM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552925
<![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552923 ]]> Bruno17 Aug 02, 2017, 10:25 AM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552923 <![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552922 btw: you don't need this &tplLast at all, but you can have
&outputSeparator=`,`
]]>
Bruno17 Aug 02, 2017, 09:52 AM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552922
<![CDATA[Re: Using getResources to display JSON data - returning correct amount of items but only uses data from the 1st resource]]> https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552921 Quote from: Bruno17 at Aug 02, 2017, 06:13 AM
do it in little steps, then show your whole code, at the last step, which works and the first step, which doesn't work.
I put both gR calls into the new resource content area and interestingly I got 2 different responses, correct and incorrect. Your suggestion returns the 3 different Latitudes perfectly, my original templates still only return data from the one resource.

Here's the 2 calls exactly:
[[!getResources? 
&parents=`26` 
&tpl=`simpleMapChunk` 
&showHidden=`1` 
&includeTVs=`1` 
&processTVs=`1` 
&limit=`20`
]]

simpleMapChunk:
[[+tv.map-latitude]]

This returns tv.map-latitude correctly, 3 different versions.
[[!getResources? 
&parents=`26` 
&tpl=`tplWrapperGMapVars` 
&tplLast=`tplWrapperGMapVarsTail` 
&showHidden=`1` 
&includeTVs=`1` 
&processTVs=`1` 
&limit=`20` 
&debug=`1`]]

tplWrapperGMapVars and tplWrapperGMapVarsTail both use the following:
lat: [[+tv.map-latitude]],
lng: [[+tv.map-longitude]],
info: '<div class="info_content"><h3>[[+tv.map-location]]</h3><p>[[+tv.map-description]]</p></div>'

This still returns 3x the same, polled from the 1st resource.
fyi, I tweaked the chunk templates a little to remove the '+' concatenation characters, just incase it was messing.

From here I don't know what to do; this testing is inserting the gR calls into [*content] but for the map to render as required I need the gR call (i.e. the json objects) to be inside the body of the google map api script. That seems catch22 to me right now, am I missing something glaringly obvious?

]]>
powellian Aug 02, 2017, 09:05 AM https://forums.modx.com/thread/102608/using-getresources-to-display-json-data---returning-correct-amount-of-items-but-only-uses-data-from-the-1st-resource?page=2#dis-post-552921