We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9149
    • 19 Posts
    [I have searched this forum extensively for posts about this with no luck, so apologies if this is an old topic that no one thinks about anymore. smiley]

    I have a fairly straightforward website that has three primary categories of content--Agents, Clients, and Books. These categories all relate to one another, and there are two TVs, [[*agentName]] and [[*clientName]] that, in particular, are shared by the Book content type. Every "Book" has both of these TV fields, every Client has [[*agentName]], and every Agent has [[*agentName]] as a TV.

    What I am attempting to do, but cannot (so far), is dynamically display related content on a page using this value (or some other approach).

    For example, on a Client Profile page, I want to be able to dynamically display all related Books (Books in the database that have the value [[*clientName]] that match the [[*clientName]] of the current page) formatted using a particular template, which I have stored as a chunk [[$bookCard]].

    Similarly, I want to display on an Agent Profile page all the Books in the database that have the value [[*agentName]] that match the [[*agentName]] of the current page), formatted using the same [[$bookCard]] chunk template.

    All Client Profile pages are child pages of a parent labeled "Clients"; Book Profile pages are child pages of a parent labeled "Books"; and Agent Profile pages are child pages of a parent labeled "Agents."

    This all seems simple and very logical, but I do not know how to do this. I've looked at getResources (the obvious place to look), and it doesn't work (or I don't know how to make it work this way, and I am using getResources all over the site). getRelated seems to produce just links to other content, which is not what I want--I want a visual display of related content. I considered Tags as a possible approach, but that seems like an unnecessary workaround.

    Am I missing something elementary, or is this "an opportunity for someone to write a new snippet"? smiley I came across some documentation that suggested a snippet containing a SQL SELECT call might do the trick, but I have no experience writing snippets.

    Thanks in advance for any help!

    Regards,
    Michael [ed. note: etherweave last edited this post 11 years, 10 months ago.]
      • 9149
      • 19 Posts
      Oops--I just realized this is posted in Revo 2.2. I'm using 2.3 just in case that's important.

      Michael
        • 3749
        • 24,544 Posts
        It might be possible to use getResources with tvFilters for this, but it would be very slow. A set of custom snippets is really the way to go, though your use case is crying out for a set of custom database tables to hold the data and the relationships. The tables could be:

        Tables ----- fields
        ---------------------------------
        Books -- id, title, author, etc.
        Clients -- id, name, phone, etc.
        Agents -- id, name phone, etc.
        BooksAgents -- bookId, AgentId
        BooksClients -- bookId, ClientId
        ClientsAgents -- clientId, agentId








          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
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Sounds like a use case for Taxonomies to me. Or MIGXdb.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            getRelated seems to produce just links to other content, which is not what I want--I want a visual display of related content.

            Reading your post, getRelated would be great for your use case. The default output is indeed a list of links, but you can completely change the output as you please using chunks so a more visual display shouldn't be an issue. Have a look at the documentation (http://rtfm.modx.com/extras/revo/getrelated) and in particular tplRow, tplOuter, returnFields and returnTVs.
              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.
              • 9149
              • 19 Posts
              Quote from: markh at Nov 22, 2014, 10:04 AM
              getRelated seems to produce just links to other content, which is not what I want--I want a visual display of related content.

              Reading your post, getRelated would be great for your use case. The default output is indeed a list of links, but you can completely change the output as you please using chunks so a more visual display shouldn't be an issue. Have a look at the documentation (http://rtfm.modx.com/extras/revo/getrelated) and in particular tplRow, tplOuter, returnFields and returnTVs.

              Thanks!

              Well, I installed getRelated and I am trying to use it, but I will be honest--the documentation is really vague and confusing. Here is an example of what I am trying and it is producing no results. I get either "No related pages found," or "Error collecting distinctive data from the resource to match against."

              [[getRelated? &resource=`21` &fields=`tv.clientName:1` &returnTVs=`bookImage,bookTitle,clientURL,clientName,bookPublisher,bookPubYear,bookAwards,bookSummary,agentURL,agentName,bookBuyURL` &contexts=`current` &limit=`10` &tplRow=`bookCard`]]


              I'm just not comprehending what the documentation instructs, but I really appreciate the help. I feel like I'm close to a solution.

              Thanks,
              Michael
                • 9149
                • 19 Posts
                OK, I now have getRelated producing accurate results, which I am able to verify via debug, but it is not displaying anything in my template (bookCard). When I attempt o use &returnTVs it doesn't make any difference. So I'm a little stuck. I've read and re-read the documentation, and I think I get it now, but I don't quite understand what's not working to get the results to display in my template...
                  • 9149
                  • 19 Posts
                  ...AND two minutes after I posted that I managed to get it to work. NEVERMIND! And THANK YOU all so much for your thoughtful feedback and suggestions. I really appreciate it.

                  Michael
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Glad I could help - and that getRelated ended up working wink What ended up being the issue?

                    The documentation is definitely quite technical, but then again it puts a lot of control in the users' hand which is why I started it off with the "how getRelated works" bit. If you have any thoughts on how to make the getRelated docs better, I'm all ears. After all, you're now the expert wink
                      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.
                      • 9149
                      • 19 Posts
                      Well, I wouldn't consider myself an "expert," but I believe I understand much better how it works. I'd be happy to help with the documentation, though! How does one do that?