Use variables in an html template
Variables in an html template define where page content and metadata should be inserted.
You can choose to insert the entire page content and/or sections of page content defined with the Named content section macro. Named content sections are useful when content appears in multiple different places within a template (e.g. with a landing page).
Items of metadata are defined with the Page metadata macro. Page metadata only appears where it is inserted in a template (not in the main content or in content sections). This enables html metadata, e.g. for a title tag, to be authored with page content.
Add a variable to an html template
Insert a variable when editing an html template by selecting the variable type from the options above the ‘Template html’ field.
This will insert the chosen variable at the cursor position.
Page metadata and Named content section macros are each given an identifying name when added to a Confluence page. When inserting a Named content section or Page metadata variable, replace the placeholder variable name with the name used in your macro. Names are case sensitive and must match exactly.
List of available variables
Variable | Code representation | Value |
---|---|---|
Entire page content | {{ content }} | Entire page content (excluding metadata defined with a Page metadata macro). |
Named content section | {{ content.nameOfYourContentSection }} | Inserts the section of page content defined by a Named content section macro with the name nameOfYourContentSection. Any metadata defined with a Page metadata macro will be excluded. |
Page metadata | {{ metadata.nameOfYourMetadataItem }} | Inserts the value of the metadata item defined with a Page metadata macro with the name nameOfYourMetadataItem. |
Variable names can be a mix of letters, numbers and dashes only, up to a maximum of 40 characters.
How templates are used to assemble an html page at publish time
When a Confluence page is published to the cloud, the content of that page is inserted into the selected template by populating the included variables (see above). This produces in the finished html page that will be published.
If a template includes no variables, no aspect of the Confluence page will be inserted and the template will be published as-is.
If a template includes a variable that is not used on the page being published (e.g. metadata.robots), that variable will be removed to ensure that the html output does not include unused variable fragments. This enables templates to safely include optional variables that are only used on some pages.