Where/How to add macro (code) being available on EVERY Confluence page?

Markus Lepper April 11, 2013

I've created a small user macro which return the page id: $content.getIdAsString()
Works quite well to add this to a page when in being in edit mode.

How, better where, to place this line to get this line automatically added (and non removalbe by users) to all confluence pages (in header or footer)?

Same question for external macros: I would like to have "Viewtracker" at bottom of every page.

I've tested "Admin > Layouts > Main layout", but did not find the right line where to add my code.

Did only get the macro-code renderdered as text (not executed) and often overlapping to the existing texts.

Thanks,
Markus

PS: Unfortunately Atlassian "lost" all my karma points when merging twom accounts...

6 answers

1 accepted

3 votes
Answer accepted
Daniela Scheiwe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

Hi! You can render macros here the same way you would use to render macros inside macros:

#set($globalHelper = $action.getHelper())
$globalHelper.renderConfluenceMacro("{MYMACRO}")

There's even a $page variable available in the page layout, so you could even use this one directly instead of your macro code.

Regarding the "where" - look through the code of the "page" layout (and blog, if you need that too) to find your desired position, it's pretty linear and quite easy to understand.

1 vote
Oli S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 16, 2013

For the documentation theme, try to insert the viewtracker macro via "Space Admin" => "Themes" => "Configure Theme" into "Messages" header or footer.

0 votes
Daniela Scheiwe
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2013

Hi, if you want it to be part of the breadcrumb navigation, you need to update the breadcrumbs.vm in C:\Program Files\Atlassian\Confluence\confluence\breadcrumbs.vm. I've tested it with v5 of confluence but should be the same for v4.

At the end of the document look for

##        </li>
    #end
    </ol>

</content>

You can just add another <li> element between #end and <ol>. $page.id is working here, so

##        &lt;/li&gt;
    #end
	&lt;li&gt;$page.id&lt;/li&gt;
    &lt;/ol&gt;

&lt;/content&gt;

results in

(no restart required for this)

Markus Lepper May 1, 2013

Thanks a lot Superuschi (Daniela? :-).

This works very well! Do you happen do know where to find more page.xxx properties; e.g. the tinyurl?

Greetings from DU to OB /Markus

Markus Lepper May 2, 2013

On admin- and profile-pages unfortunately the "$page.id" does not get rendered but is shown as plain text.

Do these pages do not have a unique id?

Regards /Markus

0 votes
Markus Lepper May 1, 2013

@Superuschi

This works, thanks!

I need to change the position, though.

The pageid and TinyURL shall be presented after the page breadcrump list

Pages / Level 1 / level 2 / instruction (PageID: xxxxx, URL: yyyyy)

I've read a lot but still am confused (due to missing knowledge) what constructs to use:

#set($globalHelper = $action.getHelper())

$!globalHelper.renderConfluenceMacro("{getpageid}")

or $sitemeshPage.getProperty("page.pageID") or similar

or ${page.id}

or {page-info:tinyurl}

or AJS.$("#pageId").val()

or ...

Nothing really works...

Thanks /Markus

0 votes
Markus Lepper April 16, 2013

Thanks Oliver..we are using the default theme where this options are n/a.

I still suppose adding "code" to "Admin > Layouts > Main layout" will help, but what and where?

0 votes
Natalie Hobson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2013

Put in a support ticket for the karma points problem - the same thing happened to me and they fixed it. :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events