Different Viewer per File type

Maybe has been answered before, but we can't find it. Is there a way to display - in the show.php file - a different viewer depending on the file type? For instance, in a collection we want to use the BookReader viewer for multipage documents, but in the same collection we also have some videos. So, is there a way to call a different viewer when the page displays a different file type.


* Using Omeka 2.1.4., with Berlin theme *


You should modify some lines in the file items/show.php in your theme in order to switch the viewer depending on the attached file or a special field.


Daniel Berthereau
Infodoc & Knowledge management

Hi Daniel

we thought so, but it's just a matter of which lines and how to modify! That's the problem!

Thanks a lot


To some degree it depends on what kinds of viewers you want, and how many different kinds. Omeka itself, and plugins like HTML5 Media provide video players and automatically use them only on video file types. Those plugins just work with the regular files_for_item and file_markup functions.

If your main special case is something like the BookReader plugin, which requires you to have a special piece of code, you probably want to just run that code instead of files_for_item for whatever item type, collection, or other piece of data you set that indicates an item should use the book reader.


You can use a specific metadata field to define the viewer to use and its options or to detect the file mime type. In Berlin, you may change the line 12 of items/show.php:

<?php echo files_for_item(); ?>


    // This field should be created before, but you can use a Dublin Core one or any existing one.
    $viewer = metadata($item, array('Item Type Metadata', 'Viewer'));
    switch ($viewer) {
        case 'Zoom':
            $file = $item->getFile();
            fire_plugin_hook('open_layers_zoom_display_file', array('file' => $file));

        case 'BookReader':
        case 'BookReader 1 page':
            echo '<div id="item-viewer">';
            fire_plugin_hook('book_reader_item_show', array(
                'view' => $this,
                'item' => $item,
                'page' => '0',
                'embed_functions' => false,
                'mode_page' => $viewer == 'BookReader' ? 2 : 1,
            echo '</div>';

       case 'Auto':
            // Code via Mime type

       case 'Default':
            echo files_for_item();

This is only the basic code. You may need to adapt some other lines (hook call), to add some checks, etc.


Daniel Berthereau
Infodoc & Knowledge management

Dear Daniel, dear John

thank you both for your answers. They are most helpful. We will test the code of Daniel and hopefully we will reach our goal. Many thanks again.