Office Template Engine
MatchPoint provides a mechanism that allows the evaluation of expressions when a Microsoft Word document is opened.
Within the document, expressions can be specified within a content control. Except for ConnectionData and DataRecord, all expression variables can be used.
Opening Office Documents with the Expression Engine
An Office template can be opened using a JavaScript method:
MP.OfficeTemplate.Open('<TemplateUrl>', '<TargetUrl>', '<DataItemUrl>')
TemplateUrl
specifies the URL that points to the Office document used as a template.TargetUrl
specifies the URL of a document library that should be the default location when the document is saved.DataItemUrl
specifies the URL of a SPListItem that should be accessed within the Office template (using the DataItem expression variable). Not mandatory.
Within the template, the expression variable Web references the web containing the template document (which may not be identical to the web from which the template was opened).
New Line breaks can be added the same way as they are added in the OOTB MatchPoint expression engine by using the new line '\n' character.
The following example shows how an office template can be opened, i.e. within a Composite Web Part:
<a href="javascript:MP.OfficeTemplate.Open('{DataItem.Url}', 'Templates')">{DataItem.Title}</a>
Office templates are opened and evaluated server-side. As a consequence, office templates do not require JavaScript with client access permissions anymore.
Placeholder Expressions within Office Documents
Within an Office template document, placeholder expressions can be configured as follows:
- Ensure that the "Developer" ribbon is visible
- Click the "File" tab.
- Click "Options"
- In the categories pane, click "Customize Ribbon"
- In the list of main tabs, select "Developer"
- Click "OK" to close the "Options" dialog box.
- Add a "Plain Text Content Control" to the document (1)
- Edit the properties of the control (2)
- Specify the following title: "MatchPoint:Expression"
- Specify an expression that should be evaluated when the document is opened. (3)
The expression will be evaluated with the same context from which the template is opened (i.e. within a MatchPoint workspace, the Workspace expression variable will return the instance of the current workspace).