Hello,
I have a snippet:
$parent = 2;
$childs = $modx->getChildIds($parent, 2);
$c = $modx->newQuery('modResource');
$c->where(array(
'published' => 1,
'id:IN' => $childs,
'hidemenu' => 0,
'template' => 2,
));
$c->sortby('id', 'DESC');
$c->limit(0);
$resources = $modx->getCollection('modResource', $c);
foreach ($resources as $resource) {
?
}
How to get comma separated json of all children?
{"some_TV_value_1": {"id":"1", "pagetitle":"Test","some_TV_name_2":"some_TV_value_2"}
Tnx!
Hi @bruno17 ,
Thank you. But i mean a bit little another idea:
my snippet should parse all emails from TV “email_req” then put results into variable in JSON. This variable is JSON-format (list of emails) for service MailGun.
'recipient-variables' => '{"bob@domain.com": {"pagetitle":"Bob", "id":1},
"bruno17@domain.com": {"pagetitle":"Bruno", "id": 2}}',
something like that, maybe:
$items = [];
foreach ($resources as $resource) {
$email = $resource->getTVValue('email');
$item = [];
$item['id'] = $resource->get('id');
$item['pagetitle'] = $resource->get('pagetitle');
$item['tv_name'] = $resource->getTVValue('tv_name');
$items[$email] = $item;
}
$json = json_encode($items);
1 Like
bobray
April 28, 2021, 1:26pm
5
Not sure what you’re doing, but the Notify extra will send emails via MailGun.
Even if Notify doesn’t meet your needs, you can look at the code of the included MailGunX class (or use that class directly).
(Notify requires the Subscribe extra to be installed.)
Yes! That’s i mean!
Thanx a lot, Bruno!
Hi @bobray ,
Yes, Bob, thank you. I’ve seen this extra. But i need another snippet, not Notify.
bobray
April 28, 2021, 2:00pm
8
You can still used the MailGunX class that comes with Notify. It will create your JSON for you.
1 Like