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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...