Smoo Posted June 25, 2019 Share Posted June 25, 2019 Rusty newbie here... I have a template called MeetingEvent, to which I've added a file field to allow uploads of multiple PDFs. The field is called meeting_event_pdf_attachment. Users may attach any number of files to this field, and it's set to provide an array of items (for simplicity). I'm having trouble getting the filename and path out of the supplied data - surely I've forgotten some bit of PHP syntax here. If I do var_dump($page->meeting_event_pdf_attachment); I get something that looks like this: object(ProcessWire\Pagefiles)#415 (2) { ["count"]=>; int(1) ["items"]=>; array(1) { ["accessibility.pdf"]=>; string(17) "accessibility.pdf" } } (In this example, my attached file is called "accessibility.pdf") var_dump($page->meeting_event_pdf_attachment->count); outputs int(1) as expected. var_dump($page->meeting_event_pdf_attachment->items); outputs NULL. I was expecting ->items to be an array - it sure looks like one. I need to be able to walk through "items" and grab the URL for the things listed there, but with it being NULL, I'm kind of perplexed as to how to do that. Should I be using a repeater instead? Any advice appreciated. Link to comment Share on other sites More sharing options...
Zeka Posted June 25, 2019 Share Posted June 25, 2019 @Smoo Take a look at documentation for Pagefiles https://processwire.com/api/ref/pagefiles/ You can loop throught like // Traversing and outputting links to all files foreach($page->files as $name => $pagefile) { echo "<li><a href='$pagefile->url'>$name: $pagefile->description</a></li>"; } 1 Link to comment Share on other sites More sharing options...
Smoo Posted June 25, 2019 Author Share Posted June 25, 2019 That did it - thanks. $page->meeting_event_pdf_attachment rather than $page->files in my case - just in case anyone else is reading this. Cheers. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now