How to get the name of the page in Velocity?

For example, I create a page called MyPage. Then on this page I write:

chrome_rTzfD8tPGk

I expect to get text MyPage. Instead, I get text WebHome:

chrome_KfpqlC8a15

I checked the API for the Document class. And looked through every function that has word name in the name of the function or description and none of the functions do what I need. For example, the getFullName() function returns MyPage.WebHome for this page. I just need MyPage without the .WebHome.

@Kulagin your created page is a non-terminal page, with full name MyPage.WebHome where the MyPage is the parent page or space and WebHome is child page also known as terminal page. Inside any other space, Main for example, you can create Main.MyPage as terminal page (you need to be advanced user to do this).
So, from MyPage.WebHome you can do $services.model.serialize($doc.documenteReference.lastSpaceReference) to obtain MyPage

1 Like

Also, @Kulagin do you wish to display the name of the page, or its title?

Name of the page, not title.

$doc.name is actually the document name and not the page name. While the UI is only referring to pages, the backend is actually based on documents and spaces and the usual pages actually are the home document (so with name WebHome) of a space.

Fortunately the API provides various helpers to manipulate the page concept, for example for your need you have

$doc.pageReference.name
2 Likes

Thanks, guys. Both solutions work.