We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33608
    • 27 Posts
    I’m using getPage to pull in some resource content and it’s working just fine.

    I am trying to filter these results down, and using a template variable that is a number to be the filter. After reading the getPage and getResources docs I figured out that maybe the JSON filter doesn’t work with template variables?

    &where=`{"template:=":8}` came straight from the docs, and all my elements are using template 2 in my site. I switched one to a different template, used this tag (&where=`{"template:=":2}`) and it worked as expected. when I try and use a template var (mine is called "hasPets", and has values of 1 or 2) the result set is always empty.

    Is this not possible with the current version of getPage/getResources?
      • 22303 MODX Staff
      • 10,725 Posts
      The tvFilters property can be used for this purpose. The where property does not have access to the appropriate tables.
        • 33608
        • 27 Posts
        Great. Thanks for the super fast response.
        I took a look at the docs for how to use tvFilters and I must not be doing something correctly.

        I’m now using this query:
        [[!getPage? &element=`getResources` &parents=`2` &includeTVs=`1` &tvPrefix=`` &limit=`5` &sortby=`` &sortbyTV=`Name` &sortdirTV=`ASC` &tvFilters=`hasPets==2` ]]
        which returns an empty set.

        When I remove that final paramater:
        [[!getPage? &element=`getResources` &parents=`2` &includeTVs=`1` &tvPrefix=`` &limit=`5` &sortby=`` &sortbyTV=`Name` &sortdirTV=`ASC` ]]
        the page displays a nice long array for each child of resource 2 that looks like this:

        Array
        (
        ...
        [hasPets] => 1
        ...
        )

        Array
        (
        ...
        [hasPets] => 2
        ...
        )
        etc. etc. etc.

        Nothing showed up in the error log, and there are no array dumps on the screen when I use &tvFilters=`hasPets==2`. Any other words of wisdom?
          • 33608
          • 27 Posts
          I’ve run into this problem as well. Was this a syntax error?
            • 3749
            • 24,544 Posts
            You need the &tpl parameter, which specifies a chunk to display the output for each selected resource.
              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