I have a template that calls getResources on a top-level parent. It only returns 1 level deep because they are all containers and I need only the list of those container resources. So this would return an array of those containers like IDs 15, 16, 17. In my examples, 15 and 16 have their own children resources, 17 does not. I’m trying to exclude 17 from further processing of templates.
I send these results to a &tpl chunk. This works fine, I’ve used &debug and I see the array with three container parents.
In the chunk I do another getResources call to see if the parent is empty by using &limit=1, I assume if it returns one resource, then I can display stuff. If it were to return empty, I can skip that container/parent.
The basic code layout of the chunk/tpl is this:
[[!getResources? &toPlaceholder=`the_listing` &limit=`1` &parents=`[[+id]]` &depth=`0` ]] [[!+the_listing:empty=`EMPTY`:notempty=` <div> [[!getResources? &tpl=`sub_items_grid` &parents=`[[+id]]` &depth=`0` ]] </div> `]]
The trick here is goofiness with the :empty and :notempty modifiers.
Oddly, if there is content inside the :empty modifier, anything at all, like
:empty=`blabla` , then the content after :notempty RUNS.
But if I have nothing in the empty part, then nothing AT ALL is output. So like
:empty=``:notempty=`div.....` In this situation, nothing outputs at all.
This is just super confusing. My test scenario is that two of the parents have children, and it should output the grid of those children. One of the containers has no children, so I would think the :empty content would display instead.
If any content is in :empty, it just works, but also outputs the empty container. If :empty is left blank, nothing outputs at all and my page is blank. Even though getResources is returning an array with content for sure.
I’ve tried every trick with cache/uncache. But I think maybe it’s the case that :empty and :notempty modifiers simply can’t be used with getResources placeholders at all?
It makes zero sense to me that if :empty is blank, nothing outputs, but if I put anything in there at all, then all the content in the :notempty attribute runs instead.
Produces no output at all. Note that this is looped three times, two of the resources should not be empty, and one is.
My inner getResources call runs 3 times including the empty parent. The page has output but includes the empty parent which I don’t want.
All I’m trying to do is skip the parent resource that has no children. My assumption is that if getResources finds nothing, it would send back an empty array, which should trigger :empty just fine.
I don’t know how else to explain this. I’m sure it’s some bug with using placeholders or I don’t know what else. The content in :empty never shows up no matter what I put there. The content in :notempty only shows up when :empty does have some content. So weird!