Macro Placeholders and Transformation Templates

This article describes how macro placeholders work and how you can modify them with transformation templates.

Note: Macro transformation templates are available as of WikiTraccs v1.20.6.

Note: Macro transformation templates got more powerful with release v1.26.1. Make sure to use a current version.

What are Macro Placeholders?

Macro placeholders are text replacements for macros and look like this:

🚧👇 Replaced ‘xyz’ macro, its content follows below (atlassian-macro-output-type==‘INLINE’)

🚧☝️ End of content of replaced ‘xyz’ macro

When migrating wiki pages from Confluence to SharePoint, WikiTraccs has to transform macros to something that SharePoint understands.

If there is no equivalent to a macro in SharePoint (which is the regular case), WikiTraccs often applies a generic transformation that replaces the macro in SharePoint with a text note.

Macro Placeholder Example

Let’s take the div macro as example. It is part of Adaptavist’s Content Formatting Macros offering.

How does the div macro look before and after having been migrated to SharePoint?

The div macro allows to apply formatting to Confluence page content, like setting the text color.

The following configuration applies a blue text color to the macro content when the macro is shown on the Confluence page:

Macro in edit mode, applying the 'color:blue' CSS style to its content, plus some other things.

Macro in view mode, displaying blue text in the Confluence page.

When migrating this macro to SharePoint, WikiTraccs discards the macro container, pulls its content out, and puts that on the page. A text placeholder highlights that this happened:

So, the result of this transformation is:

  • all content of the div macro has been migrated
  • formatting is gone with the macro container
  • a text placeholder highlights that a former div macro has been removed, but the content retained

Now, sometimes you want to get rid of that 🚧 placeholder text. You can create a custom placeholder to do that.

How to Create a Custom Macro Placeholder?

WikiTraccs allows to replace many of its built-in macro transformations using transformation templates. This can be used to replace generic macro placeholders with something different.

You can use Handlebars templates to describe how the placeholder for a macro should look. Handlebars is a markup language and templating system commonly used in web development.

Let’s say we want to remove the placeholder text for the transformed div macro, just migrating its body content.

The Handlebars template to do that looks like this:

{{!-- Don't add placeholder text, just render body --}}
{{Body}}

Some facts about above template:

  • {{Body}} is a variable, referencing the macro body; this tells WikiTraccs to just render the macro body, without additional placeholder text
  • {{!-- --}} marks a comment in the template; this is ignored by WikiTraccs

Using above transformation template, the transformed macro looks like this in SharePoint:

The 🚧 note is now gone.

Where to Put the Transformation Template File?

Custom transformation templates are stored as files in a folder.

When using WikiTraccs.GUI (the blue window), find WikiTraccs.GUI.exe and starting there, find the Templates\Transformation folder. Save your template file there.

When solely using WikiTraccs.Console (this most likely is not the case), find WikiTraccs.Console.exe and starting there, find the Templates\Transformation folder. Save your template file there.

The Transformation folder alreads contains files and should look like this (note that this can change in future WikiTraccs releases):

Each of those .hbs files contains a transformation template.

The transformation templates can apply to either

  • a single macro type (like div, or rw-ui-tabs-macro), OR
  • multiple macro types (like english,belarusian,bulgarian,canadian-en,…)

Transforming a Single Macro Type

When you want to transform a single macro type (like div), you save the transformation template in a file that carries the internal macro name in its filename and has the .hbs extension.

The file containing the transformation template for the div macro would thus be named div.hbs.

To reiterate, the steps to create a transformation template for a single macro type are:

  1. identify the internal macro name
    • you can see macro names in the storage format XML
    • note: for our div macro we see ac:name="div" in the storage format XML
  2. create a Handlebars template that describes how the custom placeholder should look
  3. save the Handlebars template in a file, in the Templates\Transformation folder
    • the filename follows the pattern MACRONAME.hbs where MACRONAME is the name of the macro
    • the file extension must be .hbs for WikiTraccs to recognize the file

Transforming Multiple Macro Types With a Single File

You can also put a special comment as first line into your .hbs file to apply the template to multiple macros, saving you the hassle to create identical files for each of those types.

Here is an example:

{{!-- applyto:english-us,english,belarusian,bulgarian,canadian-en,canadian-fr,catalan,chinese,croatian,czech,danish,dutch,estonian,finnish,french,german,greek,hindi,hungarian,icelandic,indonesian,irish,italian,japanese,korean,latvian,lithuanian,malay,maltese,norwegian-nb,norwegian,polish,portuguese,portuguese-br,romanian,russian,serbian,slovak,slovenian,spanish,swedish,thai,turkish,ukrainian,vietnamese --}}

This tells WikiTraccs to use the template for all the macros listed after the applyto: marker (internal macro names, separated by comma).

The filename doesn’t matter, as long as it has the .hbs ending.

Which Variables Are Available in Templates?

The following variables are available in transformation templates:

VariableData TypeMeaning
Bodyn/athe macro body (if the macro has one)
HasBodybooleantrue, if the macro has a body
HasNoBodybooleantrue, if the macro has no body
Details.InternalNametextinternal macro name (for example “bgcolor”)
Details.DisplayNametextmacro display name (for example “Background Color”)
TypeAsStringtext‘macro’ for macros, ‘ADF extension’ for ADF extensions, ‘unknown embedding’ otherwise
IsMacrobooleantrue, if the macro is a macro
IsMacroEmptybooleantrue, if the macro is empty; a macro that only consists of whitespace and line breaks is considered empty as well; note that body-less macros may be considered not empty, if they are known to convert to content (like a date macro which seems empty, as it has no body content, but transforms to the current date and is therefore not empty)
IsAdfExtensionbooleantrue, if the ‘macro’ is an ADF extension (so, not really a macro, but covered by macro transformation nevertheless)
HasParametersbooleantrue, if the macro has parameters
HasNoParametersbooleantrue, if the macro has no parameters
ParameterCountnumberthe number of macro parameters
Parameterscollectionmacro parameters, if the macro has any; each parameter has a Name and Value property; there is also a Links property that is populated with links parsed from the parameters
MacroXmltextcontains the raw macro XML as defined in the page’s storage format; note that you most likely need the triple brace syntax (like {{{MacroXml}}}) to work with that variable to prevent escaping
@CanTransformToTableboolean | nullinternal indicator of WikiTraccs if the macro can be transformed to a table; sometimes set to false to prevent nested table structures, sometimes set to true if nesting is unlikely; might be null
DefaultPlaceholdern/agenerates the generic macro placeholder that is output by WikiTraccs if it doesn’t know a macro; this will output a placeholder text, macro parameter values, and the body (if there is any)
RandomGuid1texta randomly generated GUID value; the variable has the same value during one macro transformation, even if used in multiple places of the template file; this can be useful if you need a random GUID at multiple places in the same template; there is also RandomGuid2 and RandomGuid3 available, providing up to 3 random GUIDs
Parameterobjectspecial variable granting access to macro parameters; see section Accessing Macro Parameters below

The following commands are available as well:

CommandMeaning
{{Exit}}Cancels processing of the current transformation template; can be used to fall back to the built-in transformation logic of WikiTraccs
{{RemoveMacro}}Removes the current macro without replacement

There are also helper functions available like String.Equal (which can be used to compare two text values for equality). Those are sometimes used by WikiTraccs’ own templates and are documented via their usage in those templates.

WikiTraccs brings some transformation template files along. In the Templates/Transformation folder, have a look at the unknown.hbs.sample file for an advanced usage example, or any of the other files.

Working with Macro Parameters

Macro parameters can be accessed via the Parameter variable.

For example the value of the macro parameter title is available via Parameter.title.Value. The parameter name (here title) is always written lowercase, even if the original macro parameter is not.

To get the value of a macro parameter (as text), you use the Parameter.paramname.Value syntax.

To get the raw XML representation of a macro parameter (as text), you use the Parameter.paramname.Xml syntax.

If the macro parameter contains links, those are accessible via the Parameter.paramname.Links collection. Each of the links can have a Title and Href property. The unknown.hbs.sample sample transformation template file shows how to enumerate links.

Sometimes WikiTraccs injects additional macro parameters mainly for internal use in its own transformation templates:

  • Parameter.wikitraccs-targetreference - added (for example) to Excerpt Include and Multiexcerpt include macros; this parameter contains an ac:link element, pointing to the page the snippet is included from; it’s used to generate a link to the source page

Multi-Pass Transformation

Macro transformation is done in three phases for each macro:

  • prebuiltin
  • builtin
  • postbuiltin

Prebuiltin can be used to decorate a macro before the built-in transformation logic kicks in.

Builtin executes the built-in transformation logic for a macro. Macro transformation templates can replace this logic.

Postbuiltin is used internally by WikiTraccs where a macro is not yet fully transformed in the builtin stage, but will be in postbuiltin.

Macro transformation templates by default are applied in the builtin stage (and replace the builtin transformation logic), unless marked otherwise.

A transformation template can be marked for a specific stage like this:

  • expand[prebuiltin].hbs - executed in prebuiltin stage
  • excerpt-include[postbuiltin].hbs - executed in postbuiltin stage
  • excerpt.hbs - no marker, builtin stage by default

Templates for SharePoint Web Parts

Have a look at the Convert Macros to SharePoint Web Parts to learn about web part generation.

Templates that generate web parts have a specific structure and the <div data-wikitraccs-webpart-template="true"> element plays a key role. It acts as marker for WikiTraccs to trigger web part generation.

Important Notes About Macro Transformation Templates

Troubleshooting

If your template is not recognized check for the following issues:

  • the template file is in the wrong folder
  • the template file doesn’t have the .hbs file ending
  • the filename doesn’t have the right pattern
  • the macro is already handled by a built-in transformation rule and thus no generic placeholder is being generated (note: there is nothing you can do about that; please get in touch and give feedback)
  • the template is malformed

Check the console log output or common log files to see if WikiTraccs loads your template.

This is how the log looks if a template could be successfully loaded:

Found 3 transformation template files in folder '<path>/Templates/Transformation', will handle one by one: ch.bitvoodoo.confluence.plugins.language.hbs div.hbs rw-ui-tabs-macro.hbs
Trying to load transformation template from file 'Templates/Transformation/div.hbs'
Compiling and registering transformation template for 'div'

Any issues should be visible here as well. You can also look at the logs to learn about the path WikiTraccs loads templates from, if you are unsure where to put them.


Macro Transformation Template Samples

This article shows sample templates.

Last modified April 12, 2025