Byline(names [, editors] [, extrasMode])
Last updated October 10, 2002
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
Generate a byline from a comma-delimited list of one or more names, in the format 'by X[, Y & Z]'. Also extensible to perform extra functions: currently included is the ability to generate links to iMDB for each name.
Return Values:
Returns a string.
Example:
Naked Lunch, #Byline("William S. Burroughs")#<br />
Boring Book, #Byline("F.P. Morden,B.J. Smith,A.B.Q. Forsythe", TRUE)#<br />
Santa Sangre, directed #Byline("Alejandro Jodorowsky", FALSE, "imdb")#<br />
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| names | List of Names. | Yes |
| editors | Boolean signifying that the list is a list of editors. Defaults to false. | No |
| extrasMode | String signifying extrasMode to use. Currently "IMDB" is support. Defaults to "none". | No |
Full UDF Source:
<cfscript>
/**
* Generates a byline from a list of names.
*
* @param names List of Names. (Required)
* @param editors Boolean signifying that the list is a list of editors. Defaults to false. (Optional)
* @param extrasMode String signifying extrasMode to use. Currently "IMDB" is support. Defaults to "none". (Optional)
* @return Returns a string.
* @author Gyrus (gyrus@norlonto.net)
* @version 1, October 10, 2002
*/
function Byline(names) {
// Initialise
var i = 0;
var name = "";
var bylineString = "";
var edited = FALSE;
var extrasMode = "none";
if (ArrayLen(Arguments) GT 1) {
edited = Arguments[2];
}
if (ArrayLen(Arguments) GT 2) {
extrasMode = Arguments[3];
}
// Loop through names
if (ListLen(names)) {
for (i=1; i LTE ListLen(names); i=i+1) {
name = ListGetAt(names, i);
// Edited?
if (edited) {
name = "#name# (ed.)";
}
// Perform extras
switch (extrasMode) {
case "imdb": {
name = "<a href=""http://uk.imdb.com/Name?#Replace(name,' ','+','ALL')#"" title=""check for information on this person on the Internet Movie Database"">#name#</a>";
break;
}
}
if (i EQ 1) {
bylineString = "by #name#";
} else if (i EQ ListLen(names)) {
bylineString = "#bylineString# & #name#";
} else {
bylineString = "#bylineString#, #name#";
}
}
}
return bylineString;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
3 day(s) ago
Will Belden added
longTime
9 day(s) ago
James Sleeman added
quickSort
19 day(s) ago
Ben Forta added
GetHostAddress
22 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)