Page Field for page name output

#1

Hi, I’m new to Grav and here is my first problem: I discovered that the Page Field outputs the complete path to the page but I need the output to be the page name only. With this output I want to generate an anchor link, e.g. #contact but with the output of the Page Field I get something like #/home/contact (it’s a modular page). What is the best practise to achieve this?

#2

Hi, maybe it might be fine slug ( see https://learn.getgrav.org/themes/theme-vars#slug )

#3

Hi @iusvar,
Thanks for your answer but it didn’t solve my problem. When I use the Page Field, the output is already “/home/contact”, so adding slug to the front end output {{ page.header.linked_page.slug }} does not work.

#4

Try only {{ page.slug }}

… if you want to know all of the Page items, write {{ page|dump }}

#5

Thank you for your help, but I used an other approach to get this fixed

#6

should generally use {{ page.url }}#something

#7

Would have been nice to know about this “other approach” since I am facing the exact same issue here.

I am looping through all the pages listed in the pages field (multiple: true). But the output is already the path, not an object. page.slug is empty. {{ page }} returns /parent/page-slug but I need the Title of the page and also the slug alone…

#8

{{page.find(page).title}} did the trick :slight_smile: