-
- 1,624 Posts
Hi,
I’m tring to output a menu with get resources but because the menu needs filtering I can’t use Wayfinder.
In Evo I would use Ditto and Wayfinder to do what I need. I would like to use getResources in Revo if possible but getResource returns a string not an array.
Is it possible to add a this as a setting to getResources?
Thanks
-
- 24,544 Posts
I’d like that too -- returning an array of resources.
In the meantime, you might be able to use getCollection() in your snippet by calling
$modx->getChildIds() for each parent, merging the arrays with array_merge() and calling $modx->getCollection().
-
- 24,544 Posts
I think it would be this:
<?php
$c = array(
array('id:IN' => $eventsIds,
'published' => '1',
'deleted' => '0',
'hidemenut' => '0',
);
$resources = $modx->getCollection('modResource', $c);
-
- 1,624 Posts
Does this work with TVs as well, meaning can I get TV values with $modx->getCollection(’modResource’, $c);?
-
- 24,544 Posts
Yes, but it’s fairly complicated. Look at the getResources code.
Once you have the array of resources, you could always loop through it and get them with:
$tv->getValue($resource->get(’id’);
or
$tv->getRenderOutput($resource->get(’id’);
-
- 1,624 Posts
gR returns an array if not tpl is provided. Unfortunately that array is actually a string.
Would it be that hard to change it to actually return an array? Maybe there is a function that reverses a string array into an array.
I’ll take a look at it when I have some time.
-
- 24,544 Posts
I thought of another route. You could call getResources with runSnippet(). I’m working on an A to Z snippet that does that. If your Tpl chunk as some token at the beginning, you could then parse them into an array with explode(). If the Tpl chunk has placeholders for the TVs, I think getResources will replace them for you.
-
- 87 Posts
Was there a resolution to this? I ran up against the same getResources "array is really string" thing tonight when trying to use it to grab a few levels of resources. Otherwise, I guess I’ll just write something that uses getCollection and loops through more than enough levels to get what I need.
Des
webandflowdesign.com
-
- 24,544 Posts
getCollection() would probably be faster (and usually easier, IMO), but it should also be easy to turn the getResources() return value into an array by putting ### at the very beginning of your Tpl chunk and doing this:
<?php
$results = getResources( ...);
$myArray = explode('###', $results);