We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36551
    • 416 Posts
    I've a got an event calendar that is filtered by categories. The client wants to be able to specify a different event category for each page.

    The getResources call is in a chunk and I can specify the category(choice) like this which works perfectly.
    [[$future-events-choice? &limit=`5` &choice=`ATT`]]
    
    [[!getResources? 
    &parents=`55` 
    &tpl=`sidebar-event-summaryitemtpl` 
    &includeTVs=`1` 
    &limit=`[[+limit]]` 
    &processTVs=`1` 
    &showHidden=`1` 
    &includeContent=`1` 
    &sortbyTV=`event-date` 
    &tvFilters=`event-type==%[[+choice]]%,event-date>=[[curDate]]`
    &sortdirTV=`ASC` 
    ]]
    

    I would like to setup a template variable, event-type, with a list of categories the client can use to filter the events on each page.

    I tried placing the TV in place of the value like this with no results.
    [[$future-events-choice? &limit=`5` &choice=`[[*event-type]]`]]

    I tried placing the TV directly in the getResources call like this, again no results.
    &tvFilters=`event-type==%[[*event-type]]%,event-date>=[[curDate]]`

    I even tried this.
    &choice=`event-type` 
    &tvFilters=`event-type==%[[+choice]]%,event-date>=[[curDate]]`

    I've tried various combinations of cached or uncached, * or +, [[+choice]] or [[+tv.choice]].

    I'm stuck. How might I accomplish this?

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

      • 3749
      • 24,544 Posts
      I'm not sure I follow what you're doing, but this might help:

      The * tells MODX to use the value from the current page. The + tells getResources to use the value from each resource it's retrieving.

      In getResources, the default tv prefix is 'tv.' so you either need to use that prefix for all references to TVs, but only the ones in the getResources tag (or you can use &tvPrefix =`` in the getResources tag).

      So this might be what you want:

      &limit=`[[*limit]]`
      &tvPrefix=`` 
      &tvFilters=`event-type==%[[*choice]]%,event-date>=[[curDate]]`


      (assuming that curDate is a snippet).

      I would try it first without the curDate filter. One issue is that the curDate snippet will return cached output, but calling it uncached probably wouldn't work because it will not be available when it's needed.

      The solution would be to have the curDate snippet set a curDate placeholder, call it uncached above everything else and use a +curDate placeholder in the getResources tag.
        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
        • 36551
        • 416 Posts
        Bob Thanks

        OK, I got my tv and placeholder names mixed up in my previous post. Got that sorted out now but still no results.

        event-type: The TV that contains all categories on all the event pages that get resources is searching
        event-filter: The TV on this page to specify the filter parameter in the getResources call.

        I removed the curdate snippet entirely and added the placeholder prefix. I also tried using the tvPrefix parameter, still no results.

        [[!getResources?
        &parents=`55`
        &tpl=`sidebar-event-summaryitemtpl`
        &includeTVs=`1`
        &processTVs=`1`
        &showHidden=`1`
        &includeContent=`1`
        &sortbyTV=`event-date`
        &tvFilters=`event-type==%[[+tv.event-filter]]%`
        &sortdirTV=`ASC`
        ]]

        Initially, I was thinking I needed to use [[*event-filter]] because this value is a TV on the current page not the pages the Get Resources is looking at in &parents=`55`. But that produced no results.

        Might this just be a problem with the order in which snippets, TV, placeholders, etc are processed? In my first example, I set the placeholder value with a parameter in the chunk containing the snippet and it works.

        Perhaps I need a snippet to set a placeholder first on this page so getResources can access that value?

        So I created this snippet called filter-by
        $myval = $modx->resource->getTVValue('event-filter');
        return $myval;

        and put this in the getResoruces call
        &tvFilters=`event-type==%[[+[[filter-by]]]]%`


        This did set the value for the filter parameter and produced results, but then all the other placeholders are empty.

        I feel like I'm really close on this. . .
          • 3749
          • 24,544 Posts
          Try this. Use your getResources tag from the post above, as is. Put this tag above it:

          [[!filter-by]]


          Use this in your filter-by snippet:

          $myval = $modx->resource->getTVValue('event-filter');
          $modx->setPlaceholder('tv.event-filter', $myval);
          return '';
          






            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
            • 36551
            • 416 Posts
            Hmmm, no results
              • 3749
              • 24,544 Posts
              Does it work when you hard-code the &tvFilters value with the value in the event-filter TV?
                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
                • 36551
                • 416 Posts
                Yes.

                The TV placed on the page displays this value: YTT ( the event category)
                If I replace this
                &tvFilters=`event-type==%[[+[[filter-by]]]]%`
                with this
                &tvFilters=`event-type==%YTT%`
                I get the proper results.

                Here's the full call. I put the TV at the top just to confirm the value of the TV
                <p>from tv: [[*event-filter]]</p>
                
                [[!filter-by]]
                [[!getResources? 
                &parents=`55` 
                &tpl=`sidebar-event-summaryitemtpl` 
                &includeTVs=`1` 
                &processTVs=`1` 
                &showHidden=`1` 
                &includeContent=`1` 
                &sortbyTV=`event-date` 
                &tvFilters=`event-type==%[[+[[filter-by]]]]%`
                &sortdirTV=`ASC` 
                ]]
                And the Snipppet
                $myval = $modx->resource->getTVValue('event-filter');
                $modx->setPlaceholder('.event-filter', $myval);
                return '';


                BTW, I reported that I earlier got results but with empty placeholders. I just tried to recreate that but could not. I hope that didn't send us on a wild goose chase.
                  • 3749
                  • 24,544 Posts
                  This is wrong:

                  $modx->setPlaceholder('.event-filter', $myval);


                  It should be:

                  $modx->setPlaceholder('event-filter', $myval);


                  (no period)

                  This is wrong also:

                  &tvFilters=`event-type==%[[+[[filter-by]]]]%`


                  It should be:

                  &tvFilters=`event-type==%[[+event-filter]]%`


                  (it has to match the placeholder set in the snippet)


                    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
                    • 36551
                    • 416 Posts
                    Bob

                    I've made these corrections. Then refreshed the page, and the filtered results appeared. I then selected a new value in the TV on the page and got no results. So I re-selected the original value in the TV and got no results. Now I'm getting nothing.

                    Hardcoding does produce results.

                    The TV is a listbox (Single-Select).
                    The Input Option Values are entered like this:
                    YTT||
                    Phone-Course||
                    EYTS

                    This page is in a 2nd context on this site, pulling content from the other context.

                    I'm happy to give you a login to look at this directly. I must be missing something somewhere. This should be so hard. smiley
                      • 3749
                      • 24,544 Posts
                      This page is in a 2nd context on this site, pulling content from the other context.

                      This could be your problem, especially if the page is protected in any way. Try creating a similar page in the same context and see if that works.
                        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