When including HTML fields into a template, you may need to format them to account for certain HTML complexities or to give your template a specific look and/or feel. This article covers the properties and settings of the HTML field.
Note: Some of the features referred to in this article require DocumentsCorePack Template Designer 10.50 and DocumentsCorePack Server 2020.169. Please ensure that both are up to date.
HTML field properties
An HTML field can be added by selecting ❶ a field within the Standard or Additional tab and clicking on the ❷ Insert Field dropdown. Under the listed options, click on ❸ Insert as HTML.
Under the field’s properties, we can adjust the ❶ Import Type and the ❷ Encoding.
The Import Type can be set to either:
- HTML Plain: (obsolete, available for compatibility reasons with older versions) no encoding is applied upon import.
- Single Encoding: (obsolete, available for compatibility reasons with older versions) For usage with style sheets and if single encoding has been applied to special characters.
- Double Encoding: To be used when style sheets are applied in MS Word on the respective field. Double encoding is applied upon import to handle special characters.
- As External Content(default): To be used when no style sheets are applied in MS Word on the respective field and the source format should be kept.
By default, As External Content is selected, and it is the native OpenXML and recommended option for inserting HTML.
For the HTML Plain, Single Encoding, and Double Encoding import types, the ❷ Enable HTML Formatting For Fields setting must be enabled in the Advanced Template Settings under the ❶ General tab in order to display their contents in the default (“Normal”) Word style. If the As External Content import type is selected, this setting does not need to be activated.
Formatting HTML fields
Changing the font of an HTML field in a template will not alter how its contents are displayed in a generated document. The field will take on the default style of the document instead. In order to change the appearance of an HTML field’s contents, the default style must be changed.
For hyperlinks within HTML fields, the “Hyperlink” style must be configured separately to distinguish the link in the generated document.
Pre-Processing HTML with Rich Text fields
Sometimes, issues may occur when inserting a rich text field as HTML into a template. This may result in unintended formatting issues. This can be resolved by implementing a HTML pre-processing rule that can match the field’s formatting with the rest of your document.
To add a HTML pre-processing rule, a SettingsKey must be added with the name “HTMLPreProcessingRules” and under the “DocumentsCorePack” product. The key value should be defined as shown below:
{
"RuleSets": [
{
"Name": "defaultrule",
"DisplayName": "Default Rule",
"Description": "This rule aims to eliminate the default font and size specifications from the HTML generated by the default RichText Control. By doing so, it ensures that the content aligns better with the styling of your document.",
"DefaultRuleSet": true,
"Rules": {
"GlobalStylingRules": [
{
"styling": "font-family"
},
{
"styling": "font-size"
}
],
"NodeTypeRules": [
{
"nodeType": "div",
"attributeRules": [
{
"attribute": "data-wrapper"
}
]
}
]
}
}
]
}
Once the SettingsKey has been saved, restart your Word instance. The Processing Rule option in the HTML field properties window will now be enabled, and the rule can be selected.
This rule can always be removed by deleting the SettingsKey. To modify or extend this HTML pre-processing rule, please contact support.
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com!