We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1212
    • 4 Posts
    Hello

    I have integrated getResources and it works great. It’s a really cool tool and concept. I wan’t to use getResources to integrate ordinary resources in a sidebox, but not on all pages, and the sidebox should be page-specific, so I want to control this with a tv. It works pretty coll, but I have one document/ page/ resource on which modx displays strange data (see "Array" below) I don’t understand. I use modx2.0.8pl running on linux hoster environment. Everything else works fine.

    I started with this, almost fully working, even the tv works fine:
    [[!getResources? &parents=`[[*integration_target]]` &tpl=`myFirstTpl`]]
    


    Then I discovered that one page the data look bad (see below) and thought this was related to my TV and changed the call:
    [[!getResources? &parents=`[[*integration_target]]` &tpl=`myFirstTpl` &tvPrefix=“]]
    


    Unfortunately the problem wasn’t gone, so I thought it could be simple to clean out the unwanted Array, but it was crazy, in strpos I could detect snippet-local asigned needles in the haystack, but not if I changed to the value passed (sounds so crazy can’t believe it myself...), and changed the call to this:
    [[!removeArray? &input=`[[!getResources? &parents=`[[*integration_target]]` &tpl=`myFirstTpl` &tvPrefix=“]]`]]
    


    The site structure looks like this:
    Home		<- page show correct data for getResouces
    Page a		<- page shows some kind of "Array"
      Page a2
    Page b
    Source-Folder   <- this folder holds folders for various "display sections"
      Homepage-News		<- this folder provides the data for Home
        Entry a
        Entry b
    


    And this strange "Array" gets displayed
    Array
    (
        [tpl] => myFirstTpl
        [tplOdd] => 
        [tplFirst] => 
        [tplLast] => 
        [sortby] => publishedon
        [sortbyTV] => 
        [sortbyTVType] => string
        [sortbyAlias] => 
        [sortbyEscaped] => 0
        [sortdir] => DESC
        [sortdirTV] => DESC
        [limit] => 5
        [offset] => 0
        [tvFilters] => 
        [depth] => 10
        [parents] => 
        [includeContent] => 
        [includeTVs] => 
        [showHidden] => 
        [showUnpublished] => 
        [showDeleted] => 
        [resources] => 
        [processTVs] => 
        [tvPrefix] => tv.
        [idx] => 1
        [first] => 1
        [last] => 1
        [toPlaceholder] => 
        [toSeparatePlaceholders] => 
        [debug] => 
        [where] => 
        [id] => 4
        [type] => document
        [contentType] => text/html
        [pagetitle] => correct page title value here
        [longtitle] => 
        [description] => 
        [alias] => 
        [link_attributes] => 
        [published] => 1
        [pub_date] => 0
        [unpub_date] => 0
        [parent] => 2
        [isfolder] => 
        [introtext] => 
        [richtext] => 1
        [template] => 1
        [menuindex] => 0
        [searchable] => 1
        [cacheable] => 1
        [createdby] => 1
        [createdon] => 2011-04-30 19:28:44
        [editedby] => 1
        [editedon] => 2011-04-30 19:57:46
        [deleted] => 
        [deletedon] => 0
        [deletedby] => 0
        [publishedon] => 2011-04-30 19:28:00
        [publishedby] => 1
        [menutitle] => 
        [donthit] => 
        [haskeywords] => 
        [hasmetatags] => 
        [privateweb] => 
        [privatemgr] => 
        [content_dispo] => 0
        [hidemenu] => 0
        [class_key] => modDocument
        [context_key] => web
        [content_type] => 1
    )
    


    Any help would be welcome. Or a hint to my error.

    Regards
    almo
      • 33968
      • 863 Posts
      This may not solve your issue, but I can tell you straight away that you don’t need to include ’tvPrefix’ unless you are asking getResources to return TVs as well as the main document fields. You don’t seem to be needing those so you could safely remove that.

      Also, make sure you always use backticks (&tvPrefix=``) in all snippet calls instead of the apostrophes you used (&tvPrefix=“)

      What is the exact value for [[*integration_target]] on that page displaying the array? Check to see that it contains only an integer, and matches with the id of an existing resource on your site.
        • 1212
        • 4 Posts
        Hi Lucas
        Thanks for your reply. I simply passed an empty... well you make me thinking... most likely an empty string? Should I pass a zero if I dont want to see any data? I expected getResources to return nothing if I didn’t pass a correct key. This might be simply wrong. I tried to pass a zero, but that even was worse and displayed the correct data plus the with every resource the array. So another question might be if it is realy wrong to expect getResources return nothing if no, not a valid resource key is provided.
        Regards
        almo
          • 25663 MODX Staff
          • 12,272 Posts
          I see two potential problems. The first is the quote marks around your tvPrefix:
          &tvPrefix=“


          It should be backticks:
          &tvPrefix=``


          Second, make sure your chunk name is actually "myFirstTpl" exactly.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 1212
            • 4 Posts
            Hi Ryan
            Thanks for the hint and shame on me, I fixed it to this: &tvPrefix=``
            Unfortunately no effect, so I removed that parameter as proposed by Lucas’ post.
            No effect either. And myFirstTpl is spelled correctly, and looks like this:
            [[+introtext]]

            (btw: I could write [[+content]] but for some unknown reason it would return blank, but maybe I have to retry...)
            Regards,
            almo
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              It doesn’t include the content by default to pick up a little speed - you can use the &includeContent=`1` parameter to force it to also include the content.

              When integration_target is empty it will most likely use the current resource as parent. You could use a conditional (like the If snippet, or an output modifier) on that TV to decide whether or not to display it.

              Are you only getting the array for "page a", or all resources?


              I don’t notice anything odd besides what’s been said already..
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 3749
                • 24,544 Posts
                That "strange array" you’re getting almost always means that getResources is not finding the tpl chunk for some reason. Make sure myFirstTpl is a chunk not a resource and try editing that chunk, deleting the name, and pasting it from the snippet tag (minus the backticks).

                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 1212
                  • 4 Posts
                  thank you all! step by step I’m getting closer.
                  The hint on &includeContent=`1` helped a lot. getResources now can display the content of multiple documents in my sidebar. Not sure why, because the Chunk now says [[+content]] or because of the flag, I will look into that later.
                  After this change instead of the "Array" now getResources return the content of its child page, thus from page a2. This occurs only for "Page a", the other pages do not display anything (so there the empty parameter magically works), and on Home where the parameter is provided it works like a charm.
                  I also double-checked and copied the string for &tpl=`myFirstTpl`, where of course the Chunks name ist myFirstTpl.
                  For the sake of curiosity I added a page b2 as child to page b. Now also page b would show the contents from page b2 in the sidebar.

                  Now, might there be something wrong the installation? I’m running some modx and never observed any problems once modx did run. However with this server I observed, that the navigation in wayfinder doesn’t update correctly, so I reinstalled everything again. But now again the new page b2 doesn’t show up in the navigation. Sorry, maybe I should put this in another post...
                    • 3749
                    • 24,544 Posts
                    Yes, if you have a Wayfinder question, you should start a new topic. smiley
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 1212
                      • 4 Posts
                      Thank you all again! Finally I could solve the issue I had with getResources. I must admit that I tried to exploit getResources in an undocumented manner and made some assumptions... that were not correct. And thanks especially for pointing me to the If-snippet and Output Modifiers I obviously wasn’t sufficiently aware of. So with these ideas I easily could solve my issue with this solution:

                      [[!If?
                         &subject=`[[*integration_target]]`
                         &operator=`NOTEMPTY`
                         &operand=``
                         &then=`<div id="extraBox">[[!getResources? &parents=`[[*integration_target]]` &includeContent=`1` &tpl=`myFirstTpl`]]</div>`
                      ]]
                      


                      And as I tried something "similar" with a snippet of my own and strpos and terribly failed I will investigate the If-snippet further to better understand modx. I pressume I made the error with the following line, which I don’t yet fully understand.

                      $modx->parser->processElementTags('',$subject,true,true);
                      


                      I tried to access the variable like this (obviously in a wrong way?):

                      the way it didn't work:
                      the call:
                      [[!myfunction? &input=`[[... some other function...]]`]] <- where other function is the call to getResources
                      
                      the snippet (resp. the line evaluating input for the appearance of string "Array"):
                      $pos = strpos(&input, `Array`);
                      


                      regards,
                      almo