Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

How to get the filename of a page

Started by Muut Archive 11 years ago · 2 replies · 414 views
11 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.

11 years ago

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

11 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 2290 9 years ago
Archive · by Muut Archive, 9 years ago
2 1506 9 years ago
Archive · by Muut Archive, 9 years ago
2 4756 9 years ago
Archive · by Muut Archive, 9 years ago
1 3572 9 years ago
Archive · by Muut Archive, 9 years ago
3 1629 9 years ago