Template authors may need to prefill the input fields of a wizard's form. For text fragments containing placeholders the projectdoc Toolbox provides a service to replace those placeholders with context or space property values. The service is located at /plugins/servlet/projectdoc/toolbox/resolve . It provides the following parameters Parameter | Description |
---|
template | The string template with placeholders to replace. | spaceKey | The key to the space whose properties are used to replace placeholders. | pageId | The identifier of the page (long) or a page reference of the format spaceKey:pageTitle (where the space key is optional and defaults to the spaceKey parameter of the service. |
The following context information can be accessed by specifying a placeholder in the template string and passing it to the service. Definition List |
---|
currentDate | The current date, formatted by the Confluence date formatter. |
---|
currentTime | The current time, formatted by the Confluence time formatter. |
---|
currentDateToken | The current date, formatted with yyyy-MM-dd . |
---|
currentUserId | The login name of the user creating the page. |
---|
currentUser | The full name of the user creating the page. |
---|
currentUserEmail | The email address of the user creating the page. |
---|
|
Example Box |
---|
title | String Template with Placeholders: Context Properties |
---|
| Code Block |
---|
New report by ${currentUser} on ${currentDate} |
|
To access space properties, simply specify the name of the property you need to be resolved. Example Box |
---|
title | String Template with Placeholders: Space Properties |
---|
| Code Block |
---|
New Release V${Version} for ${Product Name} |
|
On success (code 200) the template's placeholders are replaced or removed, if no valid for them is found. Example Box |
---|
title | Service Call from JavaScript |
---|
| The following snippet is an example on how to access the service and replace the content of an input field of a wizard's form. Code Block |
---|
| wizard.on('pre-render.page1Id', function(e, state) {
var template = encodeURIComponent("New report by ${currentUser} on ${currentDate}");
var url = AJS.contextPath()
+ "/plugins/servlet/projectdoc/toolbox/resolve?template="
+ template + "&spaceKey=" + state.wizardData.spaceKey;
AJS.$.ajax({
url: url,
success: function(data, status) {
if(status === 'success') {
state.soyRenderContext['name'] = data;
}
},
async: false
});
}); |
|
If a placeholder cannot be replaced, it is removed. The template author may define a scope by curly brackets. If at least one of the placeholder within such a scope is not replaced, the whole scope is not rendered. Example Box |
---|
title | Template with a Scope |
---|
| Code Block |
---|
| New report{ (Version ${Version})} |
Without the scope the template (with an unresolved version placeholder) would be resolved to New Report (Version ) , but with the scope the result is New Report . |
|