Windward DocumentationWindward DesignerDesigner for Microsoft OfficeFAQsHow Do I Update Values in the Header or Footer with Values from the Templates ForEach Loop?

How Do I Update Values in the Header or Footer with Values from the Templates ForEach Loop?

This article explains how to update Headers or Footers with values from the templates ForEach loop? For example the current Company Name is used in the Header while the body of the document is on that particular Company’s information.  When the ForEach loop iterates to the next Company in the loop the Header or Footer also updates the Company Name. To follow along please download this example template here.

In Microsoft Word the only way for Headers and Footers to be different is to separate them with section breaks this allows for two options “Link to Previous” which is no change at all but a repeat of the previous sections Header or Footer or Do Not Link to Previous by simply deselecting the “Link to Previous Button” from the Headers and Footers Tools ribbon in Word. In order to get Headers or Footers to update you have to use the section breaks and be sure to break the link from the previous section so that they are unique and different on each iteration of your loop.

Now how to update Out tags found in your Header or Footer with values from the current record being iterated over by your template’s ForEach loop. It will require some clever uses of our tags and input parameters along with section breaks that allow for changing Headers and Footers except in this use case the only thing changing is the value being Output by our Out tags.

These limitations are easy to notice and recognize as Headers and Footers can only see the datasource and Input Parameters they are completely blind to any tags or variables defined in the main body of your document. The workaround is simple, you create an Input Parameter and a Set tag both with the exact same variable name. What this allows is for the Header or Footer to populate their Out tags with the Input Parameters that they can see and access. Then in the main body of your template use the Set tag to update any values from the current ForEach record. This approach along with the necessary section breaks allows the Header or Footer to be updated as the ForEach loop expands. 

In this example, the Set tag variable name is named "TheCustomer". As long as your input parameter and Set tag following the opening ForEach tag is also named "TheCustomer" then that tag will update in the Header or Footer of the template after changing section breaks that allow the update to occur.

Since the first page is only a ForEach and Set tag it will not be a part of the generated output. Page two of the template is the first page of the generated output.

Review the output to notice that the Headers and Footers update with values coming from your template's ForEach loop as they expand and layout your document. 


Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.