pdoResources Where clause

Hi

I’m trying to use pdoresources to find every siblig which has an alias of ‘gallery’.
So basically, if there is an image gallery in this section, show a button for it. This is my call:

        [[!pdoResources? &parents=`[[*parent]]`  &limit=`1` &where=`[{"alias" : "gallery"}]` &tpl=`@INLINE <a class="btn" href="[[~[[*parent]]]]gallery">Image Gallery</a>` ]]

but it’s not showing anything. I can’t work out why?
I assume it s syntax error?

Thanks
Andy

You’d be correct in your assumption. Try:

[[!pdoResources? &parents=`[[*parent]]` &limit=`1` &where=`[{"alias:=" : "gallery"}]` &tpl=`@INLINE <a class="btn" href="[[~[[*parent]]]]gallery">Image Gallery</a>` ]]

Thanks for this. I changed it now, but it’s just putting a button on every page, regardless of whether or not there is a sibling with the alias of gallery. Strangely, it’s fine on pages futher down the tree (second level), but is ignored on all top level pages?
it’s actually adding a URL of this to the top level page buttons:

https://mydomain.com/0gallery

So I think that it’s something to do with the top level pages not actually having a parent?

Should I add something to the &where clause to ignore if the parent is 0?

Actually - I just tried changing the parent call to this:
&parents=[[*parent]],-0

Seems to work - but still don’t understand why it didn’t work int he first place as there are no top level pages with that alias?

For top level pages the value of [[*parent]] is 0.
So the property &parents=`[[*parent]]` in the pdoResources call evaluates to &parents=`0` .
But &parents=`0` has a special meaning, namely don’t filter the resources by parents at all.

1 Like

That’s actually a great tip that even after all these years, I never knew. Mentally bookmarked!!