We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3073
    • 28 Posts
    (Using Revo 2.2.14)

    I have one section in my site, called 'clients' - one page (or resource) per client.

    I also have a section in my site called 'news' - again, one page (resource) per news item. And a standard general news page using getResources and a tpl aggregates summaries for all the news items on that one page. Standard stuff.

    However, each news item is specifically associated with a single client. So as well as the larger news section, on each client page I'd also like to have a smaller news feed, using getResources call and tpl, but that only brings in news stories associated with that client.

    So I created a TV on the News Story template using 'Resource List' - this creates a dropdown of all clients, so the manager can choose the client this news story is associated with. This means if a new client is added it will automatically appear in this dropdown on the news story in the manager.

    But I'm not sure where to go from here.

    I have the following getResources call on my client page:
    [[!getResources? &parents=`44` &limit=`0` &tpl=`client-news-tpl` &includeTVs=`1` &showHidden=`1` &tvPrefix=`` &sortby=`publishedon` &sortdir=`DESC` ]]

    which brings in all the news stories fine.

    How do I get getResources to filter this as I want it? I'm assuming tvFilter is what I need, but cannot work out what I need to put in it. I believe the actual value stored in the Resources List TV for each resource is the resource ID, so the client page needs to only show news items where the value of the TV is the same as it's own ID. If that makes sense...

    I think what's throwing me is that I'm auto-generating the dropdown list using Resource List. If I input my own options as radio buttons or similar I think I could make it work, but I don't want to have to do it every time a new client is added.

    Or am I going about this completely the wrong way?

    Any help or pointers massively appreciated.

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

    • discuss.answer
      • 3749
      • 24,544 Posts
      If sounds like you want something like this:

      &tvFilters=`ClientName==[[+clientName]]`



      Where ClientName is the name of the TV holding the client's name and the clientName placeholder is somehow set to the name of the client you want to search for.

      If you have form-processing code, it should be able to get the client's name from the $_POST and then set the placeholder with something like this:

      $modx->setPlaceholder('ClientName', $_POST['client_name'];


      As long as that code is above the getResources tag, it should work, though it may be fairly slow if you have a lot of clients and news stories.

      This would be a more elegant (and much faster) alternative, but would require more work to set up: http://bobsguides.com/blog.html/2014/06/02/why-extend-modresource/


        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
        • 3073
        • 28 Posts
        Thanks Bob - appreciate the help.

        Your initial suggestion was the best, with a slight amend. Which is just as well as I don't have the coding skills to implement your other suggestions smiley

        So, if it helps anyone else:

        • Use a TV input type of Resource List to self-generate the client names as a dropdown list in the News page manager - allowing manager to choose which client to associate this news item with.
        • Use a getResource call on the client page calling in all News items into a summary style tpl
        • In getResources call, add the following - &tvFilters=`news-client==[[*id]]` - where news-client is the TV name.

          • 3749
          • 24,544 Posts
          I'm glad it worked for you. 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