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

Getting data from file picker field in twig template

Started by Muut Archive 10 years ago · 1 replies · 825 views
10 years ago

I have two file picker fields grabbing files from specific folders (audio and images). Well in my twig file I get the file (nameofaudio.mp3 and for the image an array object). But how do I get the url path?

TXT

.audio <!-- nameofaudio.mp3 -->
.audio.url <!-- does not work -->

.image <!-- array:1 [... -->
.image.html() <!-- does not work -->
---
10 years ago

Well, to make it work, you will need to use the path to the relevant page (folder).

TWIG

{% set audio_folder = page.find('/media/audio') %}
{% set audio = header.filepicker.audio %}

{% set image_folder = page.find('/media/image') %}
{% set image = header.filepicker.image %}

{{ audio_folder.media[audio].cache.url }}
{{ image_folder.media[image].cache.url }}

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 2955 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago