projectdoc Toolbox

The projectdoc Toolbox provides an interface for template authors to replace placeholders with space and context properties.

Audience
Expected Duration
30 min
Type

When a page author creates a page with a blueprint wizard, the template author may want to speed up page creation by providing some useful default values for the wizard or the generated page. The default texts may rely on information from the current context (such as the current date or user creating the page) or the space the page is part of (such as the name or the version of the product).

The projectdoc Toolbox supports to replace these placeholders.

 

This feature is available since version 1.11 of the projectdoc Toolbox.

The API is not considered stable until version 2.0 of the projectdoc Toolbox. Incompatible changes may be rolled out on any minor change. Usually they will be reported in the release notes.

Summary

projectdoc allows to replace placeholders at build time. Either before the blueprint wizard's form is rendered or after the author submitted the form. The replacement of placeholders is conducted at creation time of the page.

Template authors may use macros of the projectdoc Toolbox (that is Display Space Property Macro, the Display Space Attribute Macro, or the Display Document Property Macro or one of its cousins) to render space and document properties that are resolved at request time.

Replace in Wizard

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

ParameterDescription
templateThe string template with placeholders to replace.
spaceKeyThe key to the space whose properties are used to replace placeholders.
pageIdThe 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.

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.

String Template with Placeholders: Context Properties

 
New report by ${currentUser} on ${currentDate}

To access space properties, simply specify the name of the property you need to be resolved.

String Template with Placeholders: Space Properties

 
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.

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.

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.

Template with a Scope

 
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.

Replace after Submit

To replace placeholders entered by the page author the template author may specify the fields to filter in the Soy template. The names of the fields are listed in a hidden field with the name projectdoc-replace-fields-request.

Specify Fields with Placeholders

 
<input id="projectdoc-replace-fields-request" 
  type="hidden" 
  name="projectdoc-replace-fields-request" 
  value="projectdoc.doctype.common.name, projectdoc.doctype.common.shortDescription">
In this example the fields with name projectdoc.doctype.common.name and projectdoc.doctype.common.shortDescription are filtered and their placeholders, specified by the author, are replaced.

To activate the replacement process, the Context Provider is required to inherit from ProjectDocContextProvider. Please refer to add-on sources on Bitbucket for details.

 

Typically user's won't reference space properties since they usually know the value they are after better then remembering the name of a space property.

There are placeholders to use in short descriptions and placeholders to use in document names / titles.

These placeholders are prefixed by an ampersand (@) and are not replaced by the service of the previous section. If a template author uses on of them, it will be rendered verbatim in the wizard and will be substituted after the user submits the form.

Current Values in the Page

The first two examples set values to the page at creation time. It is also possible to reference space and document properties and have them replaced at request time.

Use the Display Space Property Macro, the Display Space Attribute Macro, or the Display Document Property Macro (or one of its cousins) to reference space properties, space attributes, or document properties.

Access Space Properties at Request Time

 
<ac:structured-macro ac:name="projectdoc-space-property-display-macro">
  <ac:parameter ac:name="property-name">project-version</ac:parameter>
</ac:structured-macro>

Resources

More information for template authors.

Blueprint Properties
Lists the configuration options for template authors to control page creation.
Context Provider
The main purpose of content providers is to add additional context entries for the blueprints provided by an add-on. projectdoc defines a number of context providers to be used by add-on developers.
Doctypes Introduction
A gentle introduction to page blueprints provided by doctype add-ons. The page blueprints are grouped semantically to make it easier for users to build a conceptual mind map for them.
Tour for Template Authors
This is a tour through the documentation for users that want to design their own set of templates or just want to create one or two templates.
Translate Placeholders in Short Description
The short description, stored in the blueprint context may contain placeholders that are translated to their final values.
Page Wizard Placeholder
The pages wizards provide placeholder to make page creation easier.