Repeat a Text Template

From HotDocs Wiki

Jump to: navigation, search

You can create a series of customized documents from a single template, based on answers in a repeated dialog. For example, if you want to send a letter to five people, you can gather the names and addresses in a repeated dialog and create five copies of the same letter, each with a different name and address.

To repeat a text template (create multiple versions of the same document), you can use one of several methods, depending on your situation and needs. Each of these methods produces a single word processor file, with each version of the document separated by a page break.

The first method, which works in most situations, is to select the entire template text and place it in a REPEAT instruction. Then, the variables from the repeated dialog are used in the template and a different answer is merged in the document for each repetition. If your template contains other REPEAT instructions, however, you will likely encounter problems when you try to assemble a document if one of the associated repeated dialogs is not inserted into the other. In this case, you can use one of the other two methods for repeating a text template.

The second method also uses a REPEAT instruction to repeat the entire template text, but it also includes a way to avoid problems associated with using one REPEAT instruction within another. Before the entire template is repeated, each place in the template that contains repeated information is replaced with a temporary Text variable. For example, a template may contain a list of all defendants in a case. Instead of using a REPEAT instruction where the list should appear, a simple Text variable is used. Then, at the beginning of the template, before it is repeated, the answers for these temporary Text variables are set using a computation to contain the list of repeated information.

The third method produces the same end result as the first two methods, but it handles the problem of including multiple REPEAT instructions differently than the second method. In this case, instead of using a REPEAT instruction around the entire template text, an INSERT instruction is included at the end of the template to insert another template if a new repetition is needed. That template, in turn, inserts another template for the next repetition, and so on. Because the additional pages are added using an INSERT instruction instead of a REPEAT instruction, there are no conflicts when the template contains other repeated information.

To repeat the entire text template

  1. Select the entire template text (press Ctrl+A), then click the REPEAT Field button. The REPEAT Field dialog box appears.
  2. Select a repeated dialog and click OK. The REPEAT and corresponding END REPEAT fields are inserted in the template.
  3. Insert a page break (press Ctrl+Enter) before the END REPEAT field.
  4. Select the page break, then click the IF Field button. The IF Field dialog box appears.
  5. Select IF Expression from the Field type group, then enter the following script in the Expression box (where Repeat Dialog is the name of the repeated dialog used in the REPEAT instruction):
    COUNTER < COUNT( Repeat Dialog )
  6. Click OK. The IF and corresponding END IF fields are inserted in the template.

To repeat the entire text template using Text variables for repeated information

  1. Replace repeated information with temporary Text variables. For example, to create a list of defendants, use a variable such as «Defendant List» instead of a REPEAT instruction («REPEAT Defendants:a, b, and c»«Defendant Name»«END REPEAT»).
  2. Select the entire template text (press Ctrl+A), then click the REPEAT Field button. The REPEAT Field dialog box appears.
  3. Select a repeated dialog and click OK. The REPEAT and corresponding END REPEAT fields are inserted in the template.
  4. Insert a page break (press Ctrl+Enter) before the END REPEAT field.
  5. Select the page break, then click the IF Field button. The IF Field dialog box appears.
  6. Select IF Expression from the Field type group, then enter the following script in the Expression box (where Defendants is the name of the repeated dialog used in the REPEAT instruction):
    COUNTER < COUNT( Defendants )
  7. Click OK. The IF and corresponding END IF fields are inserted in the template.
  8. Place the cursor in front of the REPEAT field, then click the Variable Field button. The Variable Field dialog box appears.
  9. Create a new Computation variable, which sets the answers for the temporary Text variables. For example, to create a list of defendants from a repeated dialog (Defendants) and save that list as the answer for a temporary Text variable (Defendant List), use the following script:
    ""
    REPEAT Defendants
      FORMAT "a, b, and c"
      RESULT + Defendant Name
    END REPEAT
    SET Defendant List TO RESULT
    ""

    See Create a Temporary Variable.

To repeat the entire text template using INSERT instructions

  1. At the top of the template, insert a variable field for a new temporary Number variable. This variable is used as an index to reference each repetition of a repeated dialog, so a variable name such as Index would make sense.
  2. In the variable field, add the word SET before the variable name, and the words TO 1 after the name. For example, with a Number variable named Index, the variable field should now look like this:
    «SET Index TO 1»
    
  3. For each variable contained in the repeated dialog used as the basis for repeating the text template, add an explicit index to the variable field. For example, if the repeated dialog contains information about defendants, you must search for those defendant variable fields and add the index variable in square brackets after the variable name, as follows:
    «Defendant Name[Index]»
    «Defendant Address[Index]»
    «Defendant Telephone[Index]»
    
    Note: If these variables are used in computations, you must also add explicit indexing to the variables in the computation scripts.
  4. At the end of the template, create a new Computation variable to insert additional repetitions. Use the following script, where Index is the name of the temporary Number variable, Defendants is the repeated dialog, and summons_insert.rtf is the name of the inserted template, which you will create later. (Use a name related to the template name. For example, if your template is summons.rtf, a name such as summons_insert.rtf will help identify it more easily as a related template.)
    IF Index < COUNT( Defendants )
      INSERT "summons_insert.rtf"
    END IF
  5. Click the Close Template button to save and close the template.
  6. Select the template at the HotDocs library window, then click the New Template button. The New Template dialog box appears.
  7. Change the name of the file by entering a new name in the File name box. Use the same name as you used in the INSERT instruction of the computation above.
  8. Click OK. The new template is created based on the original template, and it is opened in your word processor.
  9. Insert a page break (press Ctrl+Enter) at the top of the new template.
  10. Change the field that sets the index variable to increment it by one. In HotDocs 6.2 and higher, you can use the INCREMENT instruction; otherwise, you must use SET:
    «INCREMENT Index» //(HotDocs 6.2 and later)
    «SET Index TO Index + 1» //HotDocs 6.1 and earlier
    

    See Create a Temporary Variable.