I am having trouble trying to print out meta data fields eg in the header template.
I can easily hardcode the meta data tag however I am not sure of the variable or function to use to retrieve the meta data information for things such as dublin core handle ID, dublin core title, dublin core creator etc in the header. I tried using the $element_text = all_element_texts(‘item’); from the which appeared to work, however this would then create an error exception for the Browse By page.
Is there an alternative variable or function to use in the header or a way to prevent it breaking the Browse By page?
I tried that and a few other functions such as isset(), is_null() and empty() but unfortunately when there is no item parsed, it throws a fatal error. The same happens if I just do a straight print of this line: metadata(‘item’, array(‘Dublin Core’, ‘Identifier’)))
I’m running out of ideas. Any more clues would be greatly appreciated!
@Daniel_KM it appears the header.php does not pass anything in the $record which seems odd, as it continues to the else statement when I test it on an item page. There is no error exception in the Browse By page when I use this code snippet which is positive.
$record = isset($record) ? $record : (isset($item) ? $item : (isset($collection) ? $collection : (isset($file) ? $file : (isset($items) ? reset($items) : (isset($collections) ? reset($collections) : null)))));
print_r($record);
if ($record) {
$title = metadata($record, array(‘Dublin Core’, ‘Identifier’));
$identifier = metadata($record, array(‘Dublin Core’, ‘Identifier’));
echo $identifier;
// etc for the other metadata, and echo it out
}
else {
echo “
”;
}
@patrickmj When I don’t have a conditional statement to capture whether a record, item or collection is being parsed, and I purely print out $identifier = metadata($record, array(‘Dublin Core’, ‘Identifier’)); it will throw the following error on the Browse By page (I took two screenshots to show the full error message).
I have used the code snippet in the header.php but it still does not seem to print anything but the else statement. To confirm, I am editing the /omeka/web/default/themes/default/common/header.php file. If it helps, I test the page on the front end by viewing source on record item: https://repository.monash.edu/items/show/39548
In the header, the item or any other records may not be available. So the previous approach may not work in it. So another simpler way is to pass the record directly from each page in the function head(), for example in items/show.php:
Thank you for the clues @Daniel_KM!! I have passed through an $item in the head array by using the following in the item/show.php which allowed me to extract all the associated item attributes/fields including the identifier without generating an error