I’m trying to create my own shortcode, via a plugin, to display a table of some basic metadata.
I was helped by the previous discussion “Simple Pages Shortcode Question” with advice from @jflatnes and @patrickmj
and then I looked closely at both the ShortcodeCarousel and ShortcodeAnyFile plugins to construct my own.
I think I’m missing a step, though, because I’m getting an error when I try to use the shortcode:
“Omeka_View_Exception: A current item variable has not been set to this view. in /home/arkirkland/ardenkirkland.com/omekasandbox/application/views/helpers/GetCurrentRecord.php:27.”
I’ve tried it in a SimplePage with a variety of parameters and nothing seems to work, so I don’t think any specific params are the problem. It seems like the foreach $items as $item isn’t working? But that does work in the Shortcode Carousel plugin, so . . .
I have tried including or not including various parts from the other examples I followed, so I’m hoping I’m just slightly off with this particular combination.
Thanks in advance for any corrections to this code that anyone can suggest!
in ShortcodeStorageTablePlugin.php:
<?php
class ShortcodeStorageTablePlugin extends Omeka_Plugin_AbstractPlugin
{
public function setUp()
{
add_shortcode('storagetable', array('ShortcodeStorageTablePlugin', 'storagetable'));
parent::setUp();
}
/**
* Build HTML for the display of a table of storage locations and basic metadata
* @param array $args
* @param Zend_View $view
* @return string HTML to display
*/
public static function storagetable($args, $view)
{
static $id_suffix = 0;
if (isset($args['ids'])) {
$params['range'] = $args['ids'];
}
if (isset($args['tags'])) {
$params['tags'] = $args['tags'];
}
if (isset($args['sort'])) {
$params['sort_field'] = $args['sort'];
}
if (isset($args['order'])) {
$params['sort_dir'] = $args['order'];
}
if (isset($args['collection'])) {
$params['collection'] = $args['collection'];
}
if (isset($args['num'])) {
$limit = $args['num'];
} else {
$limit = 10;
}
$items = get_records('Item', $params, $limit);
$html = $view->partial('storage_table.php', array('items' => $items, 'id_suffix' => $id_suffix));
$id_suffix++;
return $html;
}
}
in storage_table.php:
<div>
<table>
<tr>
<td>Storage Location</td>
<td>Identifier</td>
<td>Title</td>
<td>Description</td>
</tr>
<?php foreach($items as $item): ?>
<tr>
<td>
<?php if (metadata('item', array('Item Type Metadata', 'Storage Location')) !='') {
echo metadata('item', array('Item Type Metadata', 'Storage Location'));
} ?>
</td>
<td>
<?php if (metadata('item', array('Dublin Core', 'Identifier')) !='') {
echo metadata('item', array('Dublin Core', 'Identifier'));
} ?>
</td>
<td>
<?php if (metadata('item', array('Dublin Core', 'Title')) !='') {
echo metadata('item', array('Dublin Core', 'Title'));
} ?>
</td>
<td>
<?php if (metadata('item', array('Dublin Core', 'Description')) !='') {
echo metadata('item', array('Dublin Core', 'Description'));
} ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>