Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
How to display specific contributors
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Based on this question, asked on the EPrints Tech list: ''How can I add the field “Thesis Advisor” from Contributors to the Abstract Pages?'' '''Note:''' The question on the tech list specified EPrints 3.4.2. The below is based on 3.3.16, but may be useful as a starting point. Below are three approaches that may do what you need. == Method 1 - EPScript function == 1) In EPScript, there is an undocumented function - <code>filter_compound_list</code> which accepts: * a field (''contributors'') * a sub-field name to filter on (''type'') * a value to filter to (''http://www.loc.gov/loc.terms/relators/THS'') * the field to return (''name'') This can produce a text-string of one field from the compound field. If a thesis had two supervisors, the following example would produce: ''Smith, John and Bond, James'' <source lang="xml"> <epc:if test="contributors"> <epc:print expr="filter_compound_list(contributors,'type','http://www.loc.gov/loc.terms/relators/THS','name')" /> </epc:if> </source> == Method 2 - EPScript logic - ''foreach'' == This method is a bit more flexible, but you have to construct the values from the parts manually. It does allow you to reference the <code>id</code> sub-field if required. It also may leave empty wrapping elements in the output (e.g. the <code>ul</code> in the example below if there are contributors, but none are the required type. <source lang="xml"> <epc:if test="contributors"> <ul> <epc:foreach expr="contributors" iterator="contr"> <epc:if test="$contr{type}='http://www.loc.gov/loc.terms/relators/THS'"> <li> <epc:print expr="$contr{name}{given}" /> <epc:print expr="$contr{name}{family}" /> <epc:if test="$contr{id}">(<epc:print expr="$contr{id}"/>)</epc:if> </li> </epc:if> </epc:foreach> </ul> </epc:if> </source> == Method 3 - Custom EPScript function == This is the most complex, but also offers the most flexibility - if you're able to understand the <code>EPrints::Script::Compiled</code> module and write your own functions. There are two parts - adding custom methods to EPScript, and calling them from the citation file. <syntaxhighlight lang="perl" line> ### This should be added to a file e.g. EPRINTS_ROOT/archives/ARCHIVEID/cfg/cfg.d/z_epscript_additions.pl # Open block { # Write into EPrints::Script::Compiled package EPrints::Script::Compiled; use strict; # Example usage in citation file: # # <epc:if test="$item.render_contributors_filtered('http://www.loc.gov/loc.terms/relators/THS',1)"> # <h2><epc:phrase ref="contributor_type_typename_http://www.loc.gov/loc.terms/relators/THS"/></h2> # <epc:print expr="$item.render_contributors_filtered('http://www.loc.gov/loc.terms/relators/THS')"/> # </epc:if> # # The first call includes the 'test' parameter, which can be used to determine whether surrounding # elements need to be displayed - in the above example the <h2>. sub run_render_contributors_filtered { my( $self, $state, $eprint, $contributor_type, $test ) = @_; if( !defined $eprint->[0] || ref($eprint->[0]) ne "EPrints::DataObj::EPrint" ) { $self->runtime_error( "Can only call render_contributors_filtered() on eprint objects not ". ref($eprint->[0]) ); } if( !defined $contributor_type ) { $self->runtime_error( "You need to specify a contributor type you want to render." ); } my @filtered_contributors = grep{ defined $_->{type} && $_->{type} eq $contributor_type->[0] } @{ $eprint->[0]->value( "contributors" ) }; if( $test ) { return [ 0, "BOOLEAN" ] if( scalar @filtered_contributors < 1 ); return [ 1, "BOOLEAN" ]; } # NB this is based on EPrints::Extras::render_related_url # It is over-complicated for this use-case, as we could just use # $state->{session}->render_name( $row->{name} ) # but if other compound fields are being used with similar code # being able to get to the 'render_value' for the sub fields is useful. my $field = $eprint->[0]->dataset->field( "contributors" ); my $f = $field->get_property( "fields_cache" ); my $fmap = {}; foreach my $field_conf ( @{$f} ) { my $fieldname = $field_conf->{name}; my $field = $field->{dataset}->get_field( $fieldname ); $fmap->{$field_conf->{sub_name}} = $field; } my $ul = $state->{session}->make_element( "ul" ); foreach my $row ( @filtered_contributors ) { my $li = $state->{session}->make_element( "li" ); $li->appendChild( $fmap->{name}->render_single_value( $state->{session}, $row->{name} ) ); if( defined $row->{id} ) { $li->appendChild( $state->{session}->make_text( " (" ) ); $li->appendChild( $state->{session}->make_text( $row->{id} ) ); $li->appendChild( $state->{session}->make_text( ")" ) ); } $ul->appendChild( $li ); } return [ $ul, "XHTML" ]; } } #End block </syntaxhighlight> The above example is also available at: https://gist.github.com/jesusbagpuss/2efc96ed05cf9121b925063a20677120 [[Category:Howto]][[Category:Snippets]][[Category:Contribute]]
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)