We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51534
    • 13 Posts
    I'm trying to show related content based on a selection made via a resource list tv, I'm not sure if resource list are the correct way to display related resources? On my website I have a couple of gyms and lots of testimonials. Each testimonial can only belong to 1 gym. So on the testimonial template I created a "resource list" tv and called it "related_gym" and entered a resource id. So now if I edit a testimonial I and go the "related_gym" tv, I get a list of gyms that I can select from. So I edited all the testimonials and chose the corresponding gym that each testimonial belongs to.

    So now on each gym template I want to show only the testimonials that belong to that gym. I've pulled all my hair out, I just cannot figure out how to filter via the "resource list" input that was selected (testimonials). The resource id of testimonials is 50. So this is the code I have below where I want to show testimonials related to the North Bay gym on the gym template when viewing a resource e.g. site.com/studio/north-bay

    [[!getResources? &parents=`50` &tpl=`testimonials_home` &tvFilter=`related_testimonials` &limit=`0` &sortdir=`DESC` &includeTVs=`1` &processTVs=`1` &includeContent=`1` &depth=`1` &sortby=`menuindex`]]


    Currently it's showing all the testimonials, instead of just the related ones. I would really appreciate if someone could point me in the right direction.
    Thanks! Johno

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

      • 30585
      • 833 Posts
      Assuming each testimonial has its own resource, this (untested) should work:
      [[getResources? 
        &parents=`50` 
        &tpl=`testimonials_home`   
        &limit=`0` 
        &includeTVs=`1` 
        &includeTVList=`related_testimonials`
        &includeContent=`1` 
        &tvFilter=`related_testimonials==%[[*id]]%` 
        &depth=`1` 
        &sortby=`menuindex`
        &sortdir=`DESC` 
      ]]
      

      Your tvFilter wasn't quite right. You basically want to match any resource that has the current gym's resource id in its related_testimonials TV.

      I've also made a few performance tweaks, such as calling getResources cached and specifying the TVs to return with includeTVList.
        A MODx Fanatic
        • 4172
        • 5,888 Posts
        be aware, if the current resource id, for example, is '5' this will not only find '5' but also 15,25,50,55 and so on
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 30585
          • 833 Posts
          Thanks Bruno. To ge the exact match, should it be: &tvFilter=`related_testimonials=[[*id]` ? Hopefully johnosmith will find this useful.
            A MODx Fanatic
            • 51534
            • 13 Posts
            Thanks guys! I've tried both and it's still showing all the testimonials, code below sad I'm wondering if I'm doing something else wrong. I realised the getResources tag could be looking for the TV "related_testimonials" in &tpl=`testimonials_home` but it's a chunk and it doesn't contain the TV. All the testimonial resources use the template testimonial_landing and does indeed have the TV "related_testimonials". Btw, the gyms are referred to as studios, hence me using studios in the tag.

            [[!getResources? &parents=`50` &tvFilter=`related_studios==%[[*id]]%` &includeTVList=`related_studios` &tpl=`testimonials_home` &limit=`5` &sortdir=`DESC` &includeTVs=`1` &processTVs=`1` &includeContent=`1` &depth=`1` &sortby=`menuindex`]]


            [[!getResources? &parents=`50` &tvFilter=`related_studios==[[*id]]` &includeTVList=`related_studios` &tpl=`testimonials_home` &limit=`5` &sortdir=`DESC` &includeTVs=`1` &processTVs=`1` &includeContent=`1` &depth=`1` &sortby=`menuindex`]]


            Thanks! [ed. note: johnosmith last edited this post 10 years, 9 months ago.]
              • 30585
              • 833 Posts
              Two things: one let's try the identical operator.
              &tvFilter=`related_studios===[[*id]]`
              

              If this doesn't give, I wonder if Bruno's migxLoopCollection can be thrown in the mix. There was a similar question that used a combination of migxLoopCollection and getResources and it seemed to work.

              If none of these things works, a custom snippet might be needed. I'll look into it when I have a chance today.
                A MODx Fanatic
                • 51534
                • 13 Posts
                Thanks Treigh. Didn't work, even tried to hardcode the id and then navigated to that specific studio. Surely something like a simple related resources which is fundamental to a CMS shouldn't be this complex? I think it's a syntax error though, since all of the 3 syntax variations I've tried makes the testimonial image disappear in the chunk that's called.

                Thanks!
                  • 30585
                  • 833 Posts
                  Sorry you're having this much trouble. For what it's worth, I built a site that had a video section where videos where linked to speakers. On each video resource, I'd select a related speaker id via a Resource List TV. With getResources, I'd then show the related video speaker on the video page with a link to that speaker's page for more info. This sounds very similar to your situation and the following call worked and still does for me:

                  [[!getCache?
                    &element=`getResources`
                    &cacheKey=`persist_videos`
                    &cacheExpires=`3600`
                    &parents=`[[*parent]]` 
                    &limit=`5` 
                    &tpl=`tplVideoSide` 
                    &includeTVs=`1` 
                    &includeTVList=`Speaker,YoutubeURL` 
                    &tvFilters=`Speaker==%[[*id]]%`
                    &showHidden=`1`    
                    &select=`{"modResource":"id,pagetitle"}`
                  ]]
                  


                  I wrapped getResources with getCache for caching purposes, but it's not required. The property we're concerned with is &tvFilters=`Speaker==%[[*id]]%`. This has always worked for me. So I'm surprised it's not playing nice for you.

                  Can you post the content of your testimonials_home chunk here?
                    A MODx Fanatic
                    • 4172
                    • 5,888 Posts
                    there are many ways to solve 'related' stuff.

                    In your case, can't you just have a subfolder on each gym 'testimonials' with all the related testimonials like

                    gyms
                    -gym A
                    --testimonials
                    ---testimonial A 1
                    ---testimonial A 2
                    gym B
                    --testimonials
                    ---testimonial B 1
                    ---testimonial B 2
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                    • discuss.answer
                      • 51534
                      • 13 Posts
                      Quote from: treigh at Dec 12, 2015, 11:22 AM
                      Sorry you're having this much trouble. For what it's worth, I built a site that had a video section where videos where linked to speakers. On each video resource, I'd select a related speaker id via a Resource List TV. With getResources, I'd then show the related video speaker on the video page with a link to that speaker's page for more info. This sounds very similar to your situation and the following call worked and still does for me:

                      [[!getCache?
                        &element=`getResources`
                        &cacheKey=`persist_videos`
                        &cacheExpires=`3600`
                        &parents=`[[*parent]]` 
                        &limit=`5` 
                        &tpl=`tplVideoSide` 
                        &includeTVs=`1` 
                        &includeTVList=`Speaker,YoutubeURL` 
                        &tvFilters=`Speaker==%[[*id]]%`
                        &showHidden=`1`    
                        &select=`{"modResource":"id,pagetitle"}`
                      ]]
                      


                      I wrapped getResources with getCache for caching purposes, but it's not required. The property we're concerned with is &tvFilters=`Speaker==%[[*id]]%`. This has always worked for me. So I'm surprised it's not playing nice for you.

                      Can you post the content of your testimonials_home chunk here?

                      Thanks Treigh, that's exactly what I want to do. I'm from an ExpressionEngine background and was very optimistic when I came across Modx, so I bought a ModxCloud account and what not, but now I'm no able to do even the simplest of things which is very frustrating. My chunk is below. The chuck is working perfectly with my getResources call, but as soon as I add includeTVList and tvFilters the image from the chunk doesn't show, besides off course that it's not pulling in related testimonials.

                      I've also attached a screenshot of my template variable setup, one thing to note that the studios/gyms are 3 levels deep e.g. Studios > Province > City.

                      <div class="client-testimonial-box">
                      	<div class="col-sm-4">
                      		<img src="[[+tv.main_image]]" class="img-responsive">
                      	</div><!-- end col -->
                      	<div class="col-sm-7 col-sm-offset-1">
                      		<h2>[[+pagetitle]]</h2>
                      		<p class="quote">[[+introtext]]</p>
                      		<a href="[[~[[+id]]]]"><span class="button">READ MORE</span></a>
                      	</div><!-- end col -->
                      </div><!-- end client-testimonial-box -->


                      Thanks!