metadata — Get metadata for a record.

View-related functions

Summary

The metadata function is the easiest and safest way to include record metadata in HTML output. metadata offers support for Element Text metadata, data stored directly in database columns, and custom metadata properties.

metadata automatically returns output HTML-escaped for inclusion in a page where appropriate. The escaping can be optionally disabled. Values also automatically passed through the Element Display Filter, though this too can be optionall disabled.

metadata($record, $metadata, $options = array())

Get metadata for a record.

Parameters:
  • $record (Omeka_Record_AbstractRecord|string) – The record to get metadata for. If an Omeka_Record_AbstractRecord, that record is used. If a string, that string is used to look up a record in the current view.

  • $metadata (mixed) – The metadata to get. If an array is given, this is Element metadata, identified by array(‘Element Set’, ‘Element’). If a string, the metadata is a record-specific “property.”

  • $options (array) – Options for getting the metadata.

Returns:

mixed

Usage

Record

The first parameter can be either a record object or the string name of a record type. The string form is used when accessing “current” records set through set_current_record or loop.

Metadata

For records that carry Element Set metadata, get the value for an element by passing the element set and element name as an array in the second parameter, e.g. array('Dublin Core', 'Title').

You can also get properties of the record by passing the name of the property as a string in the second parameter. Valid property names differ between record types. Every public property of a record (sometimes called the “columns” of the record because this is the data stored in the columns of the database) is a valid metadata name here. Many records have special additional properties that are available as well:

  • Collection

    • total_items

    • display_title

    • rich_title

  • File

    • uri

    • fullsize_uri

    • thumbnail_uri

    • square_thumbnail_uri

    • permalink

    • display_title

    • rich_title

  • Item

    • item_type_name

    • collection_name

    • permalink

    • has_files

    • file_count

    • has_thumbnail

    • citation

    • display_title

    • rich_title

Since version 2.5, all the Element Set-carrying records (Collection, File and Item) have the special property display_title that returns a simplified version of their title without any HTML tags.

Since version 2.8, the same records also have a special property rich_title that preserves only simple inline formatting HTML tags in the title (em, strong, i, b, and u), suitable for use when printing a title within HTML and allowing some formatting while avoiding interference with any wrapping markup around the title like links or headings.

The above list only covers core records. For other records, like those added by plugins, see the plugin’s documentation or the getProperty() method of the record.

Options

Valid keys for the $options array are:

  • all: If true, return an array containing all values for the field.

  • delimiter: Return the entire set of metadata as a string, where entries are separated by the given delimiter.

  • index: Return the metadata entry at the given zero-based index.

  • no_escape: If true, do not escape the resulting values for HTML entities.

  • no_filter: If true, return the set of metadata without running any filters.

  • snippet: Trim the length of each piece of text to the given length in characters.

  • ignore_unknown: If true, do not throw an error if the requested metadata element does not exist. (Since version 2.5)

  • Passing simply the string ‘all’ is equivalent to array('all' => true)

  • Passing simply an integer is equivalent to array('index' => [the integer])

Examples

Use the metadata function to get the Element Set metadata for a collection. The snippet option can be used to limit the information to only the first 150 characters.

<div class="collection record">
    <?php
        $description = metadata($collection, array('Dublin Core', 'Description'), array('snippet' => 150));
    ?>
    <?php if ($description): ?>
        <p class="collection-description"><?php echo $description; ?></p>
    <?php endif; ?>
</div>

When calling the metadata function within a loop, pass in a string of the current record type.

<h1><?php echo metadata('collection', array('Dublin Core', 'Title')); ?></h1>

The metadata function also grabs the record metadata.

<h1><?php echo metadata('simple_pages_page', 'title'); ?></h1>

See Also