How to display linked fields on browse pages?

I have items with a linked field (to another Omeka resource). It is the dcterms:creator field which is a link to s Omeka’s item of class “Person”.

I would like to display the creator after the title in the browse pages. What I call “browse page” is page presenting all the items of an item-set (item-set/6723 in the URL).

I did the modification in the theme files but, of course, Omeka S displays the url pointing to the person page instead of the title of this item (which is the name of the person).

Here is what I added in the browse.phtml of my theme:

<?php if ($auteur = $item->value('dcterms:creator')): ?>
        <div class="description"><?php echo mb_strimwidth($auteur,0,120,'[...]'); ?></div>
    <?php endif; ?>

How can I prevent that and have the name of the creator displayed (like in the item presentation page)?

How close does the MetadataBrowse Module get to what you need?

I think MetadataBrowse has a different purpose. I use it to see all items corresponding to a value. MetadataBrowse works only for page presenting one item (show) (correct me if I am wrong).

I try to display more information in multi-items pages (item-set or “browse” pages). I can add all field except the linked one.

In my website, I have a menu button pointing to a collection of articles. I have 50 titles of articles in a list and I would like to add the author. But it is a linked field and I can only print the URL.

Possibly better link to Metadata Browse.

So, it sounds like Metadata browse should apply to more pages. That’s something we can look into, though it makes the configuration a bit more complicated.

But I don’t want to have a link or create index like MetadataBrowse does.

I just want to quickly see the creator of an article when browsing between all articles (in a item-set page).

I think this is totally different from what is intended to do MetadataBrowse.

When values are resources, they are instance of ValueRepresentation. You can get the ResourceRepresentation (e.g. ItemRepresentation) using ValueRepresentation::valueResource() and then get the title using AbstractResourceEntityRepresentation::displayTitle()

The following code manage both cases: the value sometimes is a resource or a string.

<?php
use Omeka\Api\Representation\ValueRepresentation;
$auteurTerm = 'dcterms:creator';
$auteur = $item->value($auteurTerm) instanceof ValueRepresentation
        ? $item->value($auteurTerm)->valueResource()->displayTitle()
        : $item->value($auteurTerm);
if ($auteur): ?>
    <div class="description"><?php echo mb_strimwidth($auteur,0,120,'[...]'); ?></div>
<?php endif; ?>

Thanks pols12,

I have an error " Call to a member function value() on null" if I copy/paste your code.

Sorry, copy/paste issue, I’ve edited my code. You have to replace $resource variable by your $item variable.

Ok the error is fixed.

But your code displays the url instead of the title of dcterms:creator.

I will achieve to post a correct anwser… ^^

I’ve edited my code again: you have to add use Omeka\Api\Representation\ValueRepresentation; in top of your file.

No problem. Thank for the help.

Now I have ‘syntax error, unexpected ‘use’ (T_USE)’.

Ensure the previous instruction has a final semi-colon ;
Or give me the part of your code containing the use instruction, it seems to be a simple local syntax error.

Otherwise, you can remove the use instruction and replace ValueRepresentation (after instance of) with \Omeka\Api\Representation\ValueRepresentation

Ensure the previous instruction has a final semi-colon ;

Yes seems fine.

Otherwise, you can remove the use instruction and replace ValueRepresentation (after instance of) with \Omeka\Api\Representation\ValueRepresentation

it works that way!!

Final code:

<?php
	$auteurTerm = 'dcterms:creator';
	$auteur = $item->value($auteurTerm) instanceof \Omeka\Api\Representation\ValueRepresentation
		? $item->value($auteurTerm)->valueResource()->displayTitle()
		: $item->value($auteurTerm);
	if ($auteur): ?>
	    <div class="description"><?php echo mb_strimwidth($auteur,0,120,'[...]'); ?></div>
	<?php endif; ?>

Thanks again!