Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

$content.getTitle() is not rendered in user macro

Simone_Avossa May 13, 2019

Hello,

I have created a user macro that needs to print the following HTML tag:

## @noparams

<input type="hidden" name="xxx" id="xxx" value="$content.getTitle()" />

The user macro is then rendered in the page via the following expression placed in the Main Decorator of my space layout soon after the <body> tag:

...

<body #onLoadAttr() id="com-atlassian-confluence" class="$!theme.bodyClass $!sitemeshPage.getProperty("page.bodyClass") aui-layout aui-theme-default">
$helper.renderConfluenceMacro("{myusermacro}") 

...

This is, in theory, okay and I should expect to have the content title printed out as in the value attribute of my <input> tag.

However, for some reasons, the $content.getTitle() expression is not rendered in the HTML and what I get in my page HTML source code is the following output:

...

<body #onLoadAttr() id="com-atlassian-confluence" class="$!theme.bodyClass $!sitemeshPage.getProperty("page.bodyClass") aui-layout aui-theme-default">
<input type="hidden" name="xxx" id="xxx" value="$content.getTitle()" />

...

Instead of:

...

<body #onLoadAttr() id="com-atlassian-confluence" class="$!theme.bodyClass $!sitemeshPage.getProperty("page.bodyClass") aui-layout aui-theme-default">
<input type="hidden" name="xxx" id="xxx" value="My Page Title" />

...

Please, can you help me solve this mystery?

Many thanks!

2 answers

2 accepted

0 votes
Answer accepted
Alex Medved _ConfiForms_
Community Champion
May 13, 2019

Simone, in user macro you can access current page through action object, which is available is the context

${action.page.title}
Simone_Avossa May 13, 2019

Thank you @Alex Medved _ConfiForms_. I tried as suggested, but $action.page does not seem to be available either...

Alex Medved _ConfiForms_
Community Champion
May 13, 2019

Why not to use this in a page layout?

Main decorator does not know about the page, I afraid

Simone_Avossa May 14, 2019

Using Page Layout solved the issue!

0 votes
Answer accepted
Bill Bailey
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 13, 2019

I think your issue has to do with the difference in context. $content.getTitle(), is intended to be used in a page, i.e., the content is the page.

Used in the Main Decorator, there is no content per se. There is probably something like $currentPage.getTitle() that would work. You would have to look through the API docs to find the correct reference.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events