Forums

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

Taking the name of the page in the form of normal text

Jurica Petricevic
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.
February 8, 2022

Hallo Community,

i have a question. Is there a way to get the page name in text form via one type of smart value as in jira? 

 

I will try to explain where our problem lies: a page is created via template and it is necessary to provide the name of the page in the table in order to link to another page.

there can always be different depending on the name that the user enters in the macro that creates the page via the template.

 

Can someone help me here?

 

Best regards

1 answer

0 votes
Pramodh M
Community Champion
February 8, 2022

Hi @Jurica Petricevic 

Please follow the Guide here to create the User Macro

Macro Name: spacekey
Macro Title: Space Key
Description: Adds the current space key as text
Category: Confluence Content
Macro Body Processing: No macro body
Output Format: HTML
Template: $space.getKey()

Let me know if this works

Thanks,
Pramodh

Jurica Petricevic
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.
February 8, 2022

Hi @Pramodh M ,

 

as I recognized the pattern in your example I made the following macro:

$content.getTitle()

 

the problem is that this macro takes the whole name and I just need the first word. Is that possible?

Alex Medved _ConfiForms_
Community Champion
February 8, 2022

Sorry to jump into this conversation... Just trying to help

As Velocity engine version used by Confluence dost not support using get(0) you will probably need to do something like this

## @noparams

#set ($array = $content.getTitle().split(" "))
#foreach($s in $array) $s#break#end

Alex 

Jurica Petricevic
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.
February 8, 2022

@Alex Medved _ConfiForms_ we have a mistake here. I don't know exactly what the problem is but it doesn't show me the macro at all.

Alex Medved _ConfiForms_
Community Champion
February 8, 2022

Does not show you the macro or the result of the macro?

Jurica Petricevic
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.
February 8, 2022

Does not show me the macro.

Alex Medved _ConfiForms_
Community Champion
February 8, 2022

Probably because in my example I have mistyped the way you declare "no parameters" - see my updated comment now

## @noparams

based on the docs found at https://confluence.atlassian.com/doc/writing-user-macros-4485.html 

Jurica Petricevic
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.
February 8, 2022

@Alex Medved _ConfiForms_ I didn't even notice that it was a mistake there, a great job.

 

Is it possible to take the name of a directly "parent" page in this or a similar way?

if we have one tree with more pages can we say take the name directly of one larger page within this page as text?

lets say:

Space:

jurica

 jurica 1

  jurica 2

   jurica 3 (here i need text jurica 2)

Alex Medved _ConfiForms_
Community Champion
February 8, 2022

If the macro is placed on the page then you can access getParent (as in $content variable you have a reference to Page object instance)

#set ($array1 = $content.getParent().getTitle().split(" "))
#foreach($s in $array1) $s#break#end

 as per  https://docs.atlassian.com/ConfluenceServer/javadoc/7.12.2/index.html?com/atlassian/confluence/pages/Page.html

Jurica Petricevic
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.
February 9, 2022

@Alex Medved _ConfiForms_ thank you oh, you good man. And this solution works great.

Let's complicate things a little now that we're so good.

 

How to adapt the script already written above to give us only the last word from the page title? does not have to be a parent, it can be from the name of the current site.

example:

pagename: test 1 test 2 test open
result: open

 

Thx for ur help mate.

Alex Medved _ConfiForms_
Community Champion
February 9, 2022

Is this a code challenge!?

#set ($last = "")
#set ($array1 = $content.getParent().getTitle().split(" "))
#foreach($s in $array1) #set($last = $s)#end
$last

 this chemistry is needed because .get() is not supported by the version of Velocity bundled with Confluence

Jurica Petricevic
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.
February 9, 2022

@Alex Medved _ConfiForms_ it's amazing how much you helped us here.

Is this a code challenge!? -> it looks like that.

 

Is it possible to add a link in this code? Apart from pointing out the parentname, could we put a parent link instead of the name, which can then be called up by clicking on it?

#set ($array1 = $content.getParent().getTitle().split(" "))
#foreach($s in $array1) $s#break#end

Have I already gone overboard with the questions and is this already too much? I will accept any answer and understand if it is too much :)

 

Thx man once again.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events