Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

How to get the filename of a page

Started by Muut Archive 10 years ago · 2 replies · 351 views
10 years ago

Hi guys,

I'm trying to get the filename of a page. My best attempt so far is:

TWIG
{% set page_filename = page.filePath()|slice(page.path()|length)|ltrim('/') %}

Do you know any other way to achieve this? AFAIK, there is not any inbuilt function, like e.g.page.fileName(), exposed trough the page object to do this.

Thank you very much for your time and congratulations for your remarkable work.

10 years ago

You can get the same with page.template, but without .md. E.g. on a item.md page, it will return item

10 years ago

@flaviocopes
page.template

Perfect ! Thank you very much.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2956 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago