With {% for file in page.media.files %} in Twig I can iterate over the files in a specific folder. Then I can access properties, like file.url, file.name, file.extension and file.size. How can I access the creation or modification date of a file?
Community guidelines
Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.
Support
Solved by pamtbaau View solution
@myscha, Have you tried dumping the image object in Twig to reveal its properties:
TWIG
{{ dump(page.media['myimage.jpg']) }}
This will yield something like:
YAML
Array(1) object: Grav\Common\Page\Medium\ImageMedium
*gettersVariable: "items"
*items: Array(15)
type: "image"
filename: "myimage.jpg"
basename: "myimage"
extension: "jpg"
modified: 1237805256 <-- Unixepoch date
...
And finally:
TWIG
{{ page.media['myimage.jpg'].modified | date('Y/m/d') }}
@pamtbaau:
{{ page.media['myimage.jpg'].modified | date('Y/m/d') }}
Thank you very much. Using
{{ file.modified | dateTranslate(grav.config.system.pages.dateformat.long) }}
even considers the configured time format.
@myscha, Nice!
By the way... Variable system is already defined in Twig as an alias to grav.config, like many others.
Log in to reply.
Suggested topics
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 2 | 53 | 9 hours ago | ||
| 2 | 59 | 12 hours ago | ||
| 1 | 30 | 13 hours ago | ||
| 2 | 65 | 5 days ago | ||
| 2 | 56 | 5 days ago |