MODX Community

Please help with FileAttach addon

Hi, I’m using FileAttach, downloaded from Package Manager, to attach files to individual resources. Could someone please help me figure out if it’s possible to retrieve and list files from multiple child resources. With my limited skills I can only get it to retrieve files from a single resource [[FileAttach? &resource=resourceID ]]

(I’m assuming that you want the ID of the current resource.)

Try this:

[[FileAttach? &resource=`[[*id]]` ]]

Use getResources (or pdoResources) to query the children.

[[!getResources?
    &tpl=`tplChildAttachments`
    ...
]]

Then make the call to FileAttach in the template-chunk tplChildAttachments

[[FileAttach? &resource=`[[+id]]` ]]

Or you could copy the snippet FileAttach and alter this line to make it support multiple resource-ids.

Hi, thanks for this. Unfortunately I’m a noob at programming and I’m not sure what I’d need to change in the snippet to specify a parent id in order to retrieve files from multiple child id’s. Could you possibly help me out please?

Important: Don’t overwrite the snippet “FileAttach”! Duplicate it and call it “FileAttachChildren”.
Then replace the line

$c->where(array('docid' => ($resource > 0)? $resource : $modx->resource->get('id')));

with these 3 lines

$doc_id = ($resource > 0)? $resource : $modx->resource->get('id');
$children_ids = $modx->getChildIds($doc_id);
$c->where(array('docid:IN' => $children_ids));

Then call the new snippet in the parent with

[[FileAttachChildren? &resource=`[[*id]]` ]]

Thank you!! That worked brilliantly.

Now I just need to try and get it to only list future meetings. I tried this but it didn’t work

Snippet TodaysDate

<?php return date('Y-m-d H:i:s'); *****/////****** [[FileAttachChildren? &resource=`[[*id]]` &tag=`a` &tpl=`tplChildAttachments` &includeTVs=`meetingDateTV` &where=`{"meetingDateTV:<=":"[[TodaysDate]]"}` ]]

The snippet FileAttach has no properties &includeTVs or &where, so this can’t work.
To help you, I would need more information. What is the structure of your site? Is a child-resource a meeting?

And when you post code in this forum, please put lines with three back-ticks at the start and at the end of the code so it gets nicely formatted.

```//line with 3 back-ticks at the beginning
//your code here
```//line with 3 back-ticks at the end

Does this work for you?
You put this code in your parent

[[!pdoResources?
    &parents=`[[*id]]`
    &depth=`0`
    &tpl=`tplChildAttachments`
    &includeTVs=`meetingDateTV`
    &where=`{"meetingDateTV:>=":"[[!TodaysDate]]"}`
]]

and then this code in a chunk tplChildAttachments:

[[FileAttach? &resource=`[[+id]]` &tag=`a` ]]

Yes, the resources are all meetings. Hopefully this will make sense…

We have several different Committees. Each Committee meets about once a month. For each meeting there are usually two documents, an Agenda (published before the meeting), and Minutes (published after the meeting).

Each meeting is a separate resource, which is a child of a parent container (the Year the meeting took place). Each meeting has a TV for the date of the meeting.

meetingDateTV

In FileAttach for each meeting I use &tag=a or &tag=m to denote Agenda or Minutes.

Ideally I would like to be able produce a list of Agenda(s) for all forthcoming meetings (including today) from all committees, and to be able to show that list on any resources including those outside of the parent or grandparent containers.

Many thanks again.

I think it is much easier to use the version I posted above (with the use of pdoResources and a chunk) than coding the restriction for the child-resources in the snippet FileAttach yourself.

To make it easier to use it in other resources than the parent you could do this:
Put this code

[[!pdoResources?
    &parents=`[[+id]]`
    &depth=`0`
    &tpl=`tplChildAttachments`
    &includeTVs=`meetingDateTV`
    &where=`{"meetingDateTV:>=":"[[!TodaysDate]]"}`
]]

in a new chunk called Agendas.

Then put the call to this chunk in any resource you want to show the list of agendas. Add the id of the Year-resource as a property.

[[$Agendas? &id=`24`]]