Home: Support: Reference Guide: Miscellaneous Tags: <dpArray>

<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:

name="arrayName"

The name attribute is used for the name of the array you are referencing. It should be the same name you used when defining your array with <dpArrayElement></dpArrayElement>

sort="ascending|descending|asc|desc"

The sort attribute lets you sort the array either ascending or descending. Asc and Desc are aliases to ascending and descending. The default sort is ascending.

number="all|#"

By default <dpArray> will return "all" elements in the array. You may also optionally choose to loop through an array or request a specific element by using the number attribute.

return="value|count"

By default <dpArray> will return all the elements in the array. You may also optionally choose to get just a count of elements in the array. This is most commonly used in conjunction of looping through an array or checking the size of an array before displaying it.


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.