Working with Templates

Published: Tuesday, December 17th, 2013 by Chris Zieba


What are Templates?

Templates are just HTML/XML/FO files with snippets of inserted logic to represent where to populate the answers from the guided interviews. These can be created and uploaded by experienced users, or we have a collection of defaults that may suit what you are looking for.

Delimiters

LogicPull uses the following delimiters for variables <%= ... %>. For logicical conditions the equal sign can be omitted <% ... %>

Generating PDF and RTF Documents

Apacheā„¢ FOP supports multiple output formats. You can use the same template to produce both RTF and PDF documents. See here for more information.

RTF output is currently unmaintained and lacks many features compared to other output formats. Using other editable formats like Open Document Format, instead of producing XSL-FO then RTF through FOP, might give better results.

Example

Here is a basic template to generate a PDF or RTF document. You can view the template used resume demo. For more information on XSL-FO see here or here.

<?xml version="1.0"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<fo:layout-master-set>
		<fo:simple-page-master master-name="first" page-width="8.5in" page-height="11in" margin-top="0.75in" margin-bottom="0.5in" margin-left="1in" margin-right="1in">	
			<fo:region-body margin-top="0.75in" margin-bottom="0.25in"/>
			<fo:region-before region-name="header-first" extent="0.75in"/>
			<fo:region-after region-name="footer-first" extent="0.25in"/>
			<fo:region-start extent="0in"/>
			<fo:region-end extent="0in"/>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="rest" page-width="8.5in" page-height="11in" margin-top="0.5in" margin-bottom="0.5in" margin-left="1in" margin-right="1in">
			<fo:region-body margin-top="1in" margin-bottom="0.25in"/>
			<fo:region-before region-name="header-rest" extent="1in"/>
			<fo:region-after region-name="footer-rest" extent="0.25in"/>
			<fo:region-start extent="0in"/>
			<fo:region-end extent="0in"/>
		</fo:simple-page-master>
		<fo:page-sequence-master master-name="document">
		  	<fo:repeatable-page-master-alternatives>
				<fo:conditional-page-master-reference page-position="first" master-reference="first"/>
				<fo:conditional-page-master-reference page-position="rest" master-reference="rest"/>
			</fo:repeatable-page-master-alternatives>
		</fo:page-sequence-master>
	</fo:layout-master-set>
	<fo:page-sequence master-reference="document" initial-page-number="1" force-page-count="no-force">
		<fo:static-content flow-name="header-first">
			<!-- Add some content to the header here -->
		</fo:static-content>
		<fo:flow flow-name="xsl-region-body" font-size="9pt">
			<!-- Add the body content here -->
		</fo:flow>
	</fo:page-sequence>
</fo:root>

Generating Fillable PDF Forms

LogicPull also has the ability to create fillable PDF documents.

Example

Here is a basic template that can be used to populate a fillable PDF form.

<?xml version="1.0"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>
	<field name="b12c96nfparty_type">
		<value><%= master['T6_SchedOfParties_TitleType'].getAnswer().toUpperCase() %></value>
	</field>
</fields>
</xfdf>
</xsl:template>
</xsl:stylesheet>

Logic

You can create dynamic documents based on the answers supplied from the guided viewer. For more information on EJS templating please see here.

Condition

You can create conditional branch logic very easily. This logic block will only show the zip code if it has been answered in the interview. See the documentation on the isAnswered() function.

<% if (isAnswered('q2_4_zip_code')) {  %>
	<%= master['q2_4_zip_code'].getAnswer().toUpperCase() %>
<% } %>

Loops

You can create conditional branch logic very easily. This logic block will only show the zip code if it has been answered in the interview. See the documentation on the isAnswered() function.

<% for (var i = 0; i < master['counter'].getAnswer().length; i++) { %>
	<fo:block><%= master['q31_1_first_name'].getAnswer()[i] %></fo:block>
<% } %>

Looping Forms

LogicPull has the ability to generate multiple documents based on the same style sheet. For example, this is useful when you have a form that needs to be created separately for a group of clients.

You must make sure to select the correct options when adding a deliverable in the manager.

A special variable called count is available in the template to check against loop iterations. The count keeps track of how many times the document has been processed. Add some logic to the start of the template to exit the interview whence the count meets a programmed limit.

<?xml version="1.0"?>
<!-- Check to see if all the parties have been accounted for -->
<!-- The template gets looped as many times as there are parties (clients) -->
<% if (count >= (parseInt(get('PartyCount'),10))) { %>
	<% exit() %>
<% } %>

<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
	<fields>
		<field name="b12c96nfparty_type">
			<value><%= get('T6_SchedOfParties_TitleType', count).toUpperCase() %></value>
		</field>
		<!-- other fields omitted... -->
	</fields>
</xfdf>
</xsl:template>
</xsl:stylesheet>

See here to add a deliverable in the manager.