On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hello,

    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.

    This question has been answered by Bruno17. See the first response.

    [ed. note: powellian last edited this post 2 years ago.]
    • donshakespeare Reply #2, 2 years ago
      Try !uncached [[!getResources? ...
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • Quote from: donshakespeare at Jul 30, 2017, 11:52 PM
        Try !uncached [[!getResources? ...
        Thanks for the reply, unfortunately that make no difference.
        Strangely I have a couple of other instances of getResources on the same site with virtually the same parameters which work perfectly so I'm stumped on this one.

        One guess is that it's something to do with the snippet being called from within Javascript. Another guess is the returned documents with content type of JSON, but I've even tried it as HTML and get the same result!
        Maybe it's a combination of both - I've tried a few things but get the same each time.
        • eveningcoffee Reply #4, 2 years ago
          ShowHidden is in twice, try removing one. smiley
          • Quote from: eveningcoffee at Aug 01, 2017, 09:24 AM
            ShowHidden is in twice, try removing one. smiley
            Good spot smiley thanks!
            Unfort it made no diff sad

            I've edited the GR a little call to this which is a better version but still makes no difference:
            [[!getResources? 
            &parents=`26` 
            &tpl=`tpl.wrapper-GMapVars` 
            &tplLast=`tpl.wrapper-GMapVars-Tail` 
            &showHidden=`1` 
            &includeTVs=`1` 
            &processTVs=`1` 
            &limit=`20`
            ]]

            fwiw, the resources in parent 26 do need to be hidden - I alternated that but it made no difference.
            I'm running in Revo: 2.5.7
            php: 5.6.31
            mysql: 5.6.35
            • eveningcoffee Reply #6, 2 years ago
              Set &debug=`1` and check your error logs, the SQL will tell you a bit more. smiley
              • Are all the documents published? If not you will also need &showUnpublished=`1`

                Your depth is set to 1. I presume all the documents are at that level and are all children of ID 26?

                &hideContainers=`1`: Might be worth checking none of the documents have 'Container' ticked. I have had this happen before, and the document icons in the tree did not look like containers.
                  If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

                  email: andy@andytough.com | website: https://andytough.com
                • 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?
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                  • Quote from: eveningcoffee at Aug 01, 2017, 02:26 PM
                    Set &debug=`1` and check your error logs, the SQL will tell you a bit more. smiley
                    Thanks all for the replies.

                    @Andy Tough I've edited the gR call since my 1st post here, but the points you made didn't affect it at all, all docs are published and none are containers.

                    @Bruno17 - you may have a point about placeholder cacheing, leading to:

                    @eveningcoffee - I set &debug=`1` and did a full clear of the error logs, cache clear, force-refresh browser cache and the re-opened the site. Am certainly getting something in the error log pointing to the resources in question, those being: 26 (parent) and 59, 60, 61 the child resources the gR call should be rendering.

                    The run order of publishing the child docs was as that number sequence would imply, 59,60,61 and I'm only getting results from the 1st published resource: 59. The TVs in the other 2 are ignored but I get 3 returns.

                    Here's what's in the error log (I can't shed any light here - i edited it to read 'domainname'):
                    [2017-08-01 16:46:29] (ERROR @ /home/domainname/public_html/core/cache/includes/elements/modsnippet/1.include.cache.php : 201) context for 26 is web
                    [2017-08-01 16:46:29] (ERROR @ /home/domainname/public_html/core/cache/includes/elements/modsnippet/1.include.cache.php : 427) SELECT `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties` FROM `modx_site_content` AS `modResource` WHERE  ( modResource.parent IN (26,59,60,61) AND `modResource`.`deleted` = 0 AND `modResource`.`published` = 1 )  ORDER BY publishedon DESC LIMIT 20 
                    [2017-08-01 16:46:32] (ERROR @ /home/domainname/public_html/core/cache/includes/elements/modsnippet/1.include.cache.php : 201) context for 26 is web
                    [2017-08-01 16:46:32] (ERROR @ /home/domainname/public_html/core/cache/includes/elements/modsnippet/1.include.cache.php : 427) SELECT `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties` FROM `modx_site_content` AS `modResource` WHERE  ( modResource.parent IN (26,59,60,61) AND `modResource`.`deleted` = 0 AND `modResource`.`published` = 1 )  ORDER BY publishedon DESC LIMIT 20 
                    

                    Could anyone shed any light on this?
                    • the queries looking good and should return the correct resources. In fact, I think it does, but for some strange reason, getResources does only output the values of the first resource into the placeholders.

                      Try a simple call like that with a simple tpl-chunk within a normal resource

                      [[!getResources? 
                      &parents=`26` 
                      &tpl=`simpleChunk` 
                      &showHidden=`1` 
                      &includeTVs=`1` 
                      &processTVs=`1` 
                      &limit=`20`
                      ]]
                      


                      simpleChunk:
                      [[+tv.map-latitude]],
                      


                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!