Jump to content

Getting multiple items from a field

Recommended Posts

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) {
  array(1) {
    string(17) "accessibility.pdf"
(In this example, my attached file is called "accessibility.pdf")

outputs int(1) as expected.

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.

Share this post

Link to post
Share on other sites

@Smoo Take a look at documentation for 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>";


  • Like 1

Share this post

Link to post
Share on other sites

That did it - thanks.
$page->meeting_event_pdf_attachment rather than $page->files in my case - just in case anyone else is reading this.


Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...