We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23277
    • 5 Posts
    Hi,

    I have a syntax question that I have been unable to find in the forums / documentation. Basically, I want to use getResources to do two sorts, first by "eventIsFeatured", then by "eventStart". I’ve read that getResources can’t yet do multiple sorts and this is why I’ve broken it into two calls. The TV "eventIsFeatured" is a checkbox, with a check equal to 1. However, I don’t know how to test for the TV when it isn’t checked.

        [[!getResources? &parents=`[[*id]]` &depth=`0` &tpl=`eventListing` &limit=`100` &includeContent=`1` &includeTVs=`1` &tvFilters=`eventIsFeatured==1` &sortbyTV=`eventStart` &sortdirTV=`ASC` &sortby=`` ]]
        [[!getResources? &parents=`[[*id]]` &depth=`0` &tpl=`eventListing` &limit=`100` &includeContent=`1` &includeTVs=`1` &tvFilters=`eventIsFeatured!=1` &sortbyTV=`eventStart` &sortdirTV=`ASC` &sortby=`` ]]
    


    Thanks! I’m guessing this is a question with a two character reply (!= didn’t work, unfortunately)

    Scott

      • 23277
      • 5 Posts
      Ok, I think I stumbled across a bug.

      1. Checked the mysql modx2_site_tmplvar_contentvalues table and noticed that unchecked TVs didn’t have entries in the db.
      2. Turned on a default value of "0" for the TV
      3. Went into each of the resources in question, checked the box, saved, unchecked the box, saved. This created db entries. I would have expected these entries to have a value of "0" (the default value), but instead they had a value of null.
      4. Modified code to look like this:

          [[!getResources? &parents=`[[*id]]` &depth=`0` &tpl=`eventListing` &limit=`100` &includeContent=`1` &includeTVs=`1` &tvFilters=`eventIsFeatured==` &sortbyTV=`eventStart` &sortdirTV=`ASC` &sortby=`` ]]
      


      This would then pick up the empty checkboxes in the getResources call.
      5. Created a new resource and left checkbox unchecked. This did not create an entry in the DB with the default value.
      6. Looks like it’s time to do something else smiley
        • 23277
        • 5 Posts
        Ok, figured out how to do this. Ugly fix, but perhaps someone else will save a few hours.

        TEMPLATE
                [[!getResources? &parents=`[[*id]]` &depth=`0` &tpl=`eventListing` &limit=`100` &includeContent=`1` &includeTVs=`1` &tvFilters=`eventIsFeatured==1` &sortbyTV=`eventStart` &sortdirTV=`ASC` &sortby=`` ]]
                [[!getResources? &parents=`[[*id]]` &depth=`0` &tpl=`eventListing_nonFeatured` &limit=`100` &includeContent=`1` &includeTVs=`1` &sortbyTV=`eventStart` &sortdirTV=`ASC` &sortby=`` &processTVs=`1` ]]
        


        CHUNK eventListing_nonFeatured
        [[+tv.eventIsFeatured:notempty=` `:empty=`
        <div class='event'>
         ...
        </div>
        `]]