Use Google to find help fast. For example, search on "xpressdox choosefromlist".

Working with Section Breaks

Working with Section Breaks

Section breaks are used in Microsoft Word®  to separate different parts of the same document which typically have different attributes.  Such as different orientation (landscape or portrait) and different headers and/or footers.

This becomes an issue for the template author when one or more sections are included (or excluded) from the document according to some conditional logic.

Why this is an issue is that all of the information defining a section (i.e. header/footer/orientation, etc.) is kept in the Word document at the end of the section.  This becomes counter-intuitive when marking up a template.  For example:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

This section is portrait

<<If(Type = ‘Long’)>>=====================Section Break (Next Page)=======================

This section is landscape

Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.
Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.

<<End(Type = long)>>

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.

At first glance, it would appear that in the case where the data element Type is not ‘Long’ that the section between the <<If>> and <<End>> would be ignored, and what is left would be rendered in Portrait orientation.  But in fact this does not happen – what happens is the entire document (excluding the part between the <<If>> and <<End>>) is rendered in Landscape.

This is because the text which is viewed in the document as ========= Section Break(Next Page) ======= is really just put into the Word interface as a comment, it does not appear in the document itself. What does occur in the document is an invisible part at the end which contains the section information.  In fact there are two sets of section information, one just before the ====== text, and one at the end of the document.  The first contains the section information for the first section (which has “Portrait” in it) and the second section’s information is at the end of the document – far away from the <<End()>> command.  And so in this instance, when Type is not ‘Long’, the second section’s attributes trump the first, and the entire document comes out in landscape orientation.

What would be necessary to achieve one document all in portrait with the landscape section missing would be to have another section break in the document immediately after the <<End(Type = long)>> command, and to set the orientation of the page starting “Pellenteseque habitant …” to “Portrait”:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

This section is portrait

<<If(Type = ‘Long’)>>=====================Section Break (Next Page)=======================

This section is landscape

Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.

Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus.

<<End(Type = long)>>=====================Section Break (Next Page)=======================

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci.

In practice, it will probably be necessary to do a bit of trial-and-error when constructing this kind of template with conditional section formatting, as the concepts are not necessarily all that intuitive.

Similar considerations apply to using <<ForEach()>> where a Section Break is used only to introduce a new page.  But in fact, if all that is required is a Page Break, it is better to use that rather than a Section Break.  See the article on Working with Page Breaks for that discussion.

There are two templates in the My Documents\XpressDox\Samples folder which show very simply how to mark up templates where a repeating page break is required. They are the Repeating-PageBreak.xdtpl and Repeating-SectionBreak.xdtpl templates.

Leave a Reply