Glitch in Customized Item Output

Hi Patrick,

I've noticed a small glitch in the customized item output you helped me build a couple of months ago:

http://omeka.org/forums/topic/customizing-item-output

When a field is empty, the title still gets displayed. For example, the primary text field still shows up here:

http://www.nineteenthcenturydisability.org/items/show/6

Any suggestions for a workaround?
Thanks!
Karen

If we're very lucky, on the Appearance -> Settings admin page make sure that the "Display Empty Elements" checkbox is not checked. I'm not entirely convinced that's what the issue is, but it's worth a shot as an easy-peasy first stab.

If easy-peasy doesn't work, I suspect it's in this (I'm copying from the earlier discussion):

if(isset($elementsForDisplay['Item Type Metadata'])) {
    $wantedElements['Primary Source Text'] = $elementsForDisplay['Item Type Metadata']['Text'];
}

Instead of that, maybe amend it to:

if(isset($elementsForDisplay['Item Type Metadata']) && isset($elementsForDisplay['Item Type Metadata']['Text']) {
    $wantedElements['Primary Source Text'] = $elementsForDisplay['Item Type Metadata']['Text'];
}

That's just a first couple guesses, and I suspect the second is closer to working, but we'll see!

I haven't got a line of code that looks exactly like the one above. I tried slapping in the new line in a couple of different ways to no avail. I may be missing something.

Here's what my record-metadata.php file looks like:

<?php if(isset(get_view()->item)): //check if this looks like an item show page ?>
<?php
//dig through the elements for display that are passed into this file
//put it all into a new array of just the elements we want
//this should let you collect the elements you want in the order you want
//follow this pattern to get more or change the order

$wantedElements = array();
$wantedElements['Image'] = $elementsForDisplay['Dublin Core']['Rights'];
$wantedElements['Introduction'] = $elementsForDisplay['Dublin Core']['Description'];
$wantedElements['Primary Source Text'] = $elementsForDisplay['Document Item Type Metadata']['Text'];
$wantedElements['Source'] = $elementsForDisplay['Dublin Core']['Source'];
$wantedElements['Date'] = $elementsForDisplay['Dublin Core']['Date'];
$wantedElements['Further Reading'] = $elementsForDisplay['Dublin Core']['Relation'];
$wantedElements['Contributor'] = $elementsForDisplay['Dublin Core']['Contributor'];
?>

<div class="element-set">
    <?php foreach ($wantedElements as $elementName => $elementInfo): ?>
    <div id="<?php echo text_to_id(html_escape("$elementName")); ?>" class="element">
        <h3><?php echo html_escape(__($elementName)); ?></h3>
        <?php foreach ($elementInfo['texts'] as $text): ?>
            <div class="element-text"><?php echo $text; ?></div>
        <?php endforeach; ?>
    </div><!-- end element -->
    <?php endforeach; ?>
</div><!-- end element-set -->

<?php else: ?>

<?php foreach ($elementsForDisplay as $setName => $setElements): ?>
<div class="element-set">
    <h2><?php echo html_escape(__($setName)); ?></h2>
    <?php foreach ($setElements as $elementName => $elementInfo): ?>
    <div id="<?php echo text_to_id(html_escape("$setName $elementName")); ?>" class="element">
        <h3><?php echo html_escape(__($elementName)); ?></h3>
        <?php foreach ($elementInfo['texts'] as $text): ?>
            <div class="element-text"><?php echo $text; ?></div>
        <?php endforeach; ?>
    </div><!-- end element -->
    <?php endforeach; ?>
</div><!-- end element-set -->
<?php endforeach; ?>

// Loop through our array of fields, breaking out the label and value.
    foreach ($fields as $label => $value) {

        // Only display the field if it has a value.
        if ($value) {

            // Construct the HTML for displaying the label and value.
            $html .= '<div class="field field-'. text_to_id($label) .'">'
                   . '<h2>'.$label.'</h2>'
                   . '<div class="field-value">'
                   . $value
                   . '</div>'
                   . '</div>';

        }

    }

    return $html;

<?php endif; ?>

Maybe something in the last bit of html, or the line at the very beginning?

Thanks for posting the code you have. Helps much!

This is still a bit of a guess until I recreate the item types etc you have, but I'm guessing that the check needs to happen around this line:

$wantedElements['Primary Source Text'] = $elementsForDisplay['Document Item Type Metadata']['Text'];

I'm hoping that this will do the trick, replacing that line:

if(!empty($elementsForDisplay['Document Item Type Metadata']['Text'])) {
    $wantedElements['Primary Source Text'] =  $elementsForDisplay['Document Item Type Metadata']['Text'];
}

The idea is to check to see if the Document Item Type Metadata Text element really does have a value, and only add it to the list of wantedElements if it is not empty.

At least that's my best guess now!

Woohoo! That did the trick! Thank you so much! Karen