Taking the name of the page in the form of normal text
Asked by Jurica Petricevic:

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


Answers:
author: Pramodh M
body: Hi [@Jurica Petricevic](/t5/user/viewprofilepage/user-id/3994191)

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

comments: author: Jurica Petricevic
body: Hi [@Pramodh M](/t5/user/viewprofilepage/user-id/3691224) ,

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?


author: Alex Medved _ConfiForms_
body: 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


author: Jurica Petricevic
body: [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630) we have a mistake here. I don't know exactly what the problem is but it doesn't show me the macro at all.


author: Alex Medved _ConfiForms_
body: Does not show you the macro or the result of the macro?


author: Jurica Petricevic
body: Does not show me the macro.


author: Alex Medved _ConfiForms_
body: 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>


author: Jurica Petricevic
body: [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630) 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)


author: Alex Medved _ConfiForms_
body: 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>


author: Jurica Petricevic
body: [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630) 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.


author: Alex Medved _ConfiForms_
body: 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


author: Jurica Petricevic
body: [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630) 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.


Tags: confluence-server

data-center