Collection Variables: Introduction and Lists

Doc Auto Team
Doc Auto Team
  • Updated

Collection variables are used to specify which category of data you would like to pull information from.

 

Accessing variables within a collection

The syntax for collection variables or loops always requires:

{#} the hashtag - opens a loop

{/} the forward slash - closes a loop

There are two ways to get information from a collection. In the example below we will use the example of the directors collection that contains the directors Jessica Day, Winston Schmidt, and Nicholas Miller.

 

Example Code

Result

1

{director_name}

Jessica Day

2

{#directors}{name}, {/}

Jessica Day, Winston Schmidt, Nicholas Miller,

In example 1, we were able to access the director’s name using a _ to access the {name} variable within the directors collection.

In example 2, we opened the collection with a # and used the single variable {name} to access all of the directors names in the collection. We must also remember to close the collection with the closing tag {/}.

The location of the closing tag is very important and could cause errors if mishandled. 

 

Loops

Example 2 above is an example of a loop. To begin looping through collections, we use the opening tag # before the collection name and use closing tags {/} when we want to end the loop.

Other ways to loop through collections is through a List or a Table.

 

Lists

Generated lists can be ordered or unordered. There are different ways to code lists.

-w:p

The -w:p function is used to create bulleted lists without an additional line. Use -w:p in the opening tag and remember to close the tag with {/}.

Example

You want to create a list of officers including their name and office.

Example Code

Result

  • {-w:p officers}{name} - {office}{/}

  • Jessica Pearson - President

  • Harvey Specter - Secretary

  • Louis Litt - Treasurer

You can use any type of bulleted or numbered list format offered by Microsoft Word.

 

You can also create a list using collection loops.

Example Code

Result

  1. {#officers}{name} - {office}
    {/}
  1. Jessica Pearson - President

  2. Harvey Specter - Secretary

  3. Louis Litt - Treasurer

 

Make sure that the closing tag is not bulleted. If it is bulleted, you will be left with an empty bullet at the end of your list.