Mailing List Archive

[Bricolage-General] Retrieving/Displaying Contributors?
When working with templates, how can I retrieve
the contributors associated with a story?

I looked in the docs, but still can't figure
it out. I want to print out the Writer names
and contact information that I've associated
as Contributors to my stories.

-- Andy.

----------------------------------------------
Andrew C. Baio
Webmaster, Dimensional Fund Advisors
andrew.baio@dfafunds.com (310) 576-1126
----------------------------------------------

_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] Retrieving/Displaying Contributors? [ In reply to ]
On Mon, 25 Feb 2002, Andrew Baio wrote:

> When working with templates, how can I retrieve
> the contributors associated with a story?
>
> I looked in the docs, but still can't figure
> it out. I want to print out the Writer names
> and contact information that I've associated
> as Contributors to my stories.

Here's some code I wrote to produce a byline string of the form:

by Sam Tregar, Sammy Hagar (Photographer) and Martin Short (Illustrator)

That is, Writers first with no type in parens followed by other
contributors with a singular version of their type name in parens. It's
written to be used in an HTML::Template burner .pl file but it should be
easy to port to a Mason .mc file if that's what you're using.

my( $byline, @contributors, $person, $type, @writers );
foreach $person( $story->get_contributors() ) {
$type = $person->get_grp->get_name();
if( $type eq 'Writers' ) {
push( @writers, $person->get_name() );
} else {
$type = s/s$//;
push( @contributors, $person->get_name() . "($type)" );
}
}

# sort writer's names alphebetically by last name
@writers = sort by_lastname @writers;

# push writers onto front of contributor's array...
unshift( @contributors, @writers );

# build byline string
if( @contributors <= 0 ) {
$byline = "";
} else {
if( @contributors > 1 ) {
$byline = "by " . join( ", ", @contributors );
} else {
$byline = "by " . $contributors[0];
}
}

# set the byline var in the template
$template->param( byline => $byline );

-sam



_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general