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?
-
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.
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?
I’ve run into this problem as well. Was this a syntax error?
You need the &tpl parameter, which specifies a chunk to display the output for each selected resource.