Digital Asset Management for all your ProcessWire media

Accessing Custom Properties in a Media Manager Object

Any fields added to the Media Manager templates (media-manager- audio, document, image and video) are all available as properties in each MediaManager Object.

For instance, let us say you added the fields summary (a text field), biography (a repeater field) and book_quantity (an integer field) to your media-manager-image template. You can easily access these fields from your Media Manager Field. Assume that the Media Manager field is named authors and has been added to a templated by the same name. Media has been added to the field and we now want to view them, together with the their respective custom/extra fields (summary, biography and book_quantity) in the frontend. Here is how we would do it:


<?php

  $out = "";
  
  // get the media manager field on the page
  $authors = $page->authors;
  // $authors is a MediaManagerArray so we traverse it
  foreach($authors as $author) {
    // $author is a MediaManager Object
    // custom fields in it are also Objects of their own type

    // summary field (text field)
    $out . $author->summary;
    
    // book quantity field (integer)
    $out .= $author->book_quantity;

    // biography (repeater)
    // this is a repeater, we traverse it
    foreach($author->biography as $bio) {
      // do something with repeater properties
      
    }

  }

  echo $out;

The key things to remember are that your customer fields are also objects and that they may return collections (WireArray, PageArray, etc) that would need traversing. If you wanted to, you can of course use the newer WireArray methods such as each() for traversal rather than using foreach.