Create Component Templates

Introduction

Organizations often have multiple templates containing identical sections (e.g. a standard terms and conditions clause). Copying and pasting sections like this into multiple templates isn't scalable - each time an edit is required, you'd have to make the edit in every template.

Luckily, S-Docs allows you to create component templates, which are templates that can be merged into other templates as a merge field similar to {{{{!YourTemplateNameHere}}}}.

Component templates allow you to easily insert a template into as many templates as you'd like - and only have to edit one template if edits are required. Additionally, you don't have to worry about complicating the structure of the template where the component is used; you can insert an incredibly complex template into another in just one line.

Create Component Templates

To create a component template, create an S-Docs template like normal and set the Template Format to "Component." Templates with a Template Format of "Component" will not show up in the template selection list when users are generating documents, because they cannot be generated by themselves. Instead, they'll be available to insert into other templates under the Other Templates tab of the Insert Field menu.

Note: Some versions of S-Docs do not have "Component" as an allowed value in the Template Format picklist; nonetheless, you can add "Component" to the set of picklist values yourself by navigating to Setup > Object Manager > SDoc Template > Fields & Relationships > Template Format > Values  > New.

Build your component template like a normal S-Docs template. Note that the Header, Footer, Page Settings, and other template configuration tabs are not available for component templates, since these settings are dictated by the parent template.


Note: Component templates support <nullprefix>, <nullpostfix>, <allprefix>, and <allpostfix> tags.

Components for the DOCX Format

The standard "Component" format is HTML-based, and will work with other HTML-based formats like PDF, DOC, and HTML.

To merge a component into a DOCX template, you will need to use the "Component (DOCX)" format and create a template in Word to upload just as with a standard DOCX template. This format can be added to the Template Format picklist the same as the "Component" item, and, once created, can be inserted using the standard DOCX merge field formatting [{{{{!My Component Template}}}}] or with the Insert Field tool as shown below.

Note: Like standard "Component" templates, template files for the "Component (DOCX)" format should not include headers, footers, or file configurations like password protection. These configurations will be covered by the parent DOCX template.

Using Template Formats Other Than "Component"

S-Docs templates can be included in other template as components regardless of template format. However, templates with a Template Format other than "Component" will not be available to insert using the Insert Field tool; you will have to write the syntax manually.

In addition, templates that don't have a Template Format of "Component" will show up to users as standalone documents that can be generated by themselves, unless you uncheck the Available for Use and Initially Visible checkboxes.

Insert Component Templates

Components can be inserted into parent templates in multiple different ways. In this example, we will be inserting our component into the following invoice template:

Note that the invoice template has different Related to Type and Template Format fields than the component template.

That's because the Related to Type, Template Format, and other template fields of the component are irrelevant; they have no effect. The parent template's fields will be used, and the terms and conditions fields will be ignored. Thus, you can choose arbitrary fields for your component templates and insert them into any other kind of template.

Use Merge Fields

In the template editor for the parent template, place the cursor where you'd like your component to appear, and click Insert Field.

Navigate to the Other Templates tab, select the name of the component template, and click Insert to insert it as a merge field where your cursor was. You can also click Copy to Clipboard to copy the component merge field syntax and manually paste it into the template.

Note: Any template with a Template Format set to "Component" will show up in this list, regardless of its Related To Type object, as long as the Available for Use and Initially Visible checkboxes are checked for the component.

As you can see, the component merge field was added to our document. Components merge fields can be added anywhere in your parent template; even the header or footer.

When the parent template is generated, the component content will be merged where specified.

Use Template Tags

Components can also be merged into parent templates using <template> tags in the template source. The terms and conditions component from this example could be merged into the parent template by including the following in the template source:

<template>Terms and Conditions</template>

Dynamically Reference Components

You can use merge fields to determine which component name will be called and merged into the parent template.

For example, say you have two components named “Component A” and “Component B,” and your Opportunity record has a custom field Component Type with values A and B.

In your document, you can reference your component name using syntax similar to one of the following methods:

<template>Component {{!Opportunity.Component_Type__c}}</template>

{{{{!Component {{!Opportunity.Component_Type__c}}}}}}

The value of the Component Type field on the Opportunity would determine which component is merged.

Note: Dynamic component references are only supported for components with the same base object as the parent template. We recommend calling components using <template> tags when using this feature.

Use Components to Display Record List Data

Components can be configured to repeatedly generate in a parent template for each record in a specified list of records. Click here to learn how to set up this feature.

Special Component Types

Certain template formats require special syntax and come with unique considerations when using them as components.

PDF-Upload Components

You can insert PDF-Upload templates as components within regular PDF templates.

Considerations:

1. You must add the componentType="pdf-upload" attribute to your component syntax. For example, if your PDF-Upload template was named "PDF Upload Component," the merge field syntax would look like one of the following:

{{{{!PDF Upload Component componentType="pdf-upload"}}}}

<template componentType="pdf-upload">PDF Upload Component</template>

2. HTML tags cannot open before the component merge field and close after it; you must close all tags before the PDF-Upload component is inserted. Upon document generation, the content before the component, the component itself, and the content after the component are wrapped in separate <body> tags.

3. The PDF-Upload component will force a page break and be merged in as separate page(s).

4. Be sure the PDF template and the PDF-Upload component template have the same page orientation and dimensions.

Tags: , ,

Was this helpful?