<dpArray>
D E F I N I T I O N:
<dpArray> allows you to sort and display values you set in an array using <dpArrayElement>. It is most commonly used to display unique and sorted lists of authors in your database.
<dpArray
name="arrayName"
sort="ascending|descending|asc|desc"
number="all|#"
return="value|count"
>
A T T R I B U T E S:
E X A M P L E S:
<dpArray name="myList" sort="ascending">
myList has <dpArray name="myList" return="count"> values.
<dpLoop var="i" from="1" to="<dpArray name="myList" return="count">">
<dpArray name="myList" number="<dpVar i>" sort="ascending">
</dpLoop>
D E T A I L S:
Defining and Using an <dpArray>
The following will define an array named "myList". It will then load two values into the array. Notice that the values require a key which is used for sorting, and a value which is used when you display the array.
T A G C O D E:
<dpArrayElement name="myList" key="gerken, wil">
Wil Gerken<br>
</dpArrayElement>
<dpArrayElement name="myList" key="forbes, collin">
Collin Forbes<br>
</dpArrayElement>
The following will sort the values in the "myList" array and display them all.
<dpArray name="myList" sort="ascending" number="all">
which will return:
Collin Forbes<br>
Wil Gerken<br>
Give it a try in the tag tester.
E F F E C T:
Creating an Author List
The following produces a two column layout of unique authors sorted alphabetically. To add links to the author archive page, modify the array element to include the desired link. For instance:
<a href="../authors/<dpAuthorID number="<dpVar i>">"><dpAuthor number="<dpVar i>"></a><br>
T A G C O D E:
<dpQuery issue="all" realm="author">
<dpLoop var="i" from="1" to="<dpAuthor return="count">">
<dpArrayElement name="myList" key="<dpAuthor number="<dpVar i>"
format="lastfirst">">
<dpAuthor number="<dpVar i>"><br>
</dpArrayElement>
</dpLoop>
</dpQuery>
<dpComment>
Set middle marker and offset by one if uneven so left side gets extra length.
</dpComment>
<dpVar top="<dpArray name="myList" return="count">">
<dpVar middle="<dpMath <dpVar top>/2>">
<dpIf <dpMath <dpVar top>%<dpVar middle>> != 0>
<dpVar middle="<dpMath <dpVar middle>+1>">
</dpIf>
<dpComment>
Render dual column table
</dpComment>
<table border="1" cellpadding="5" cellspacing="1">
<tr>
<td valign="top">
<ul>
<dpLoop var="i" from="1" to="<dpVar top>">
<li><dpArray name="myList" sort="ascending" number="<dpVar i>">
<dpIf <dpVar i> = <dpVar middle>>
</ul>
</td>
<td valign="top">
<ul>
</dpIf>
</dpLoop>
</ul>
</td>
</tr>
</table>
E F F E C T:
| Home: Support: Reference Guide: Miscellaneous Tags: <dpArray> | Questions? Comments? Please write support@desert.net. |