We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37165
    • 89 Posts
    I am using MigxDB (on MODX REV 2.2.13-pl) to create a bunch of custom galleries. One of the TV's I am using when adding images is a multi-select listbox of resources. I have created a TV named it "exhibition_resource_id" and have brought it into my MigxDB. I'd like this TV to publish a list of links on the front end. It works great when there is only 1 value, but does not work when more than one value is selected. How can I make it work with multiple values? Here is my code:

    Call to MigxDb in my template:
    							[[!migxLoopCollection?
    							&packageName=`artwork`
    							&classname=`artWorks`
    							&sortConfig=`[{"sortby":"exhibition_resource_id","sortdir":"ASC"}]`
    							&where=`{"artist_resource_id":"[[*id]]"}`
    							&tpl=`tpl_artist_page_past_exhibtions`
    							]]	


    My template chunk:
    <li><a href="[[~[[+exhibition_resource_id]]]]">[[getResourceField? &id=`[[+exhibition_resource_id]]` &field=`page title`]]</a></li>


    The above works when one value is selected. However if I select 2 values the second one is ignored and only one link is produced on the front end. This is because MigxDB outputs multiple values in the +exhibition_resource_id like this :

    9||12


    But what I need is for it to recognize that there are two value here and wrap each value in the chunk above. Resulting in two links on the front end. I'm not sure if I need some kind of snippet, or to alter the MigxDB output settings for that TV or use javascript to create some kind of array.

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

      • 4172
      • 5,888 Posts
      try:

      &where=`{"artist_resource_id":"[[*id]]","OR:artist_resource_id:LIKE":"[[*id]]||%","OR:artist_resource_id:LIKE":"%||[[*id]]||%","OR:artist_resource_id:LIKE":"%||[[*id]]"}`


      or have a custom-processor, which makes sure, you have any number surrounded by ||

      than you could just use:
      &where=`{"artist_resource_id:LIKE":"%||[[*id]]||%"}`

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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37165
        • 89 Posts
        Quote from: Bruno17 at Apr 22, 2014, 04:14 PM
        try:

        &where=`{"artist_resource_id":"[[*id]]","OR:artist_resource_id:LIKE":"[[*id]]||%","OR:artist_resource_id:LIKE":"%||[[*id]]||%","OR:artist_resource_id:LIKE":"%||[[*id]]"}`


        or have a custom-processor, which makes sure, you have any number surrounded by ||

        than you could just use:
        &where=`{"artist_resource_id:LIKE":"%||[[*id]]||%"}`


        Thanks for this although it doesnt produce the correct result. My "artist_resource_id" always has only one value. It's the "exhibition_resource_id" that has multiple values. I need a list of all "exhibition_resource_id" that are associated with the "artist_resource_id" defined in the where call. Right now when I add in two values for "exhibition_resource_id" the output looks like this " 9||12" when the chunk formats the resource ids, they only produce a link for the first ID and not the second. Does that make sense?

          • 4172
          • 5,888 Posts
          sorry, I see.
          Then try:

          [[getResources?
          &parents=`0`
          &depth=`10`
          &resources=`[[+exhibition_resource_id:replace=`||==,`]]`
          &tpl=`tpl_exhibition_link`
          ]]


          chunk tpl_exhibition_link:
          <li><href="[[~[[+id]]]]">[[+pagetitle]]</a></li>
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 37165
            • 89 Posts
            That just gave me a list of every page on my site. Maybe I'm not understanding correctly or explaining well. Here is an example:

            In my MigxDB lets say I have 3 art works and all have artist_resource_id and exhibition_resource_id. Both of those TV's are resource lists :

            Artwork 1
            artist_resource_id = 9
            exhibition_resource_id = 8

            Artwork 2
            artist_resource_id = 9
            exhibition_resource_id = 8||12

            Artwork 3
            artist_resource_id = 4
            exhibition_resource_id = 16


            This Call (which is called on the template for all resources )grabs all the Artworks associated with whatever page we are on. So If I'm on resource 9 this code will pull all images from MIGXDB that have an artist resource of 9. In the example above it would pull in Artwork1 and Artwork 2. If I changed to resource 4 it would only get Artwork 3

            migxLoopCollection?
            &packageName=`artwork`
            &classname=`artWorks`
            &sortConfig=`[{"sortby":"exhibition_resource_id","sortdir":"ASC"}]`
            &where=`{"artist_resource_id":"[[*id]]"}`
            &tpl=`tpl_artist_page_past_exhibtions`
            ]]  


            The above works. Let say we are looking at resource 9 I want a list of exhibition_resource_id that are associated with artwork on page 9. The way I'm using the chunk above it gives me a link for exhibition_resource_id 8 two times. It does not see exhibition resource 12 because it is after the `11`
            I want it to give me two links. One for '8' and one for '12' because those resources are associated with artworks being called in the migxloopcollection.


            If I was looking at resource 4, I would expect to see just one link for exhibition resource 16
            • discuss.answer
              • 4172
              • 5,888 Posts
              I was wrong with &parents=`0`

              Inside the chunk tpl_exhibition_link, I think it should be:

              [[getResources?
              &parents=`-1`
              &resources=`[[+exhibition_resource_id:replace=`||==,`]]`
              &tpl=`tpl_exhibition_link`
              ]]


              This should convert
              8||12
              to
              8,12
              and only show this resources and create a list of Links for exhibitions
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 37165
                • 89 Posts
                Bruno! this totally works and some of your other answers helped with some other issues. I would have never thought to use getResources inside the migxDB call. Thank you!

                One more question, how would I go about deleting duplicates in the links list? So in my example above both Artwork #1 and Artwork #2 both use exhibition_resource_id 8. Right now it shows up twice. Is there an easy way to just make it show up once?
                  • 4172
                  • 5,888 Posts
                  you can try to collect all exhibitions before calling getResources with

                  [[migxLoopCollection?
                  &packageName=`artwork`
                  &classname=`artWorks`
                  &where=`{"artist_resource_id":"[[*id]]"}`
                  &tpl=`@CODE:[[+exhibition_resource_id]]`
                  &outputSeparator=`||`
                  &toPlaceholder=`resource_ids`
                  ]]
                  
                  [[getResources?
                  &parents=`-1`
                  &resources=`[[+resource_ids:replace=`||==,`]]`
                  &tpl=`tpl_exhibition_link`
                  ]]
                  

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

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 37165
                    • 89 Posts
                    Yes! Works great. Thank you so much for all your help!