Hello all. I’m trying to get my custom theme working with Grav and I’m having trouble getting filepicker to work. I think it’s something simple and I’m just overlooking it, although I’ve been trying for weeks to figure this out.
The below YAML allows the filepicker field to appear on the admin side when Media Upload is selected. The dropdown appears and I can select a file that I’ve uploaded. However when I save it, my selection isn’t persisted in the .md file.
I figured it’s because the field doesn’t start with a period (because the other fields start with a period), so I changed it from mediaField.media to .media, dropping mediaField at the beginning. But that just causes a red banner to appear that says “Not Found” any time I try to open the drop down (which now doesn’t populate).
Two questions:
- Is my YAML correct, and if not what am I missing?
- I want the filename of the chosen file from the filepicker to show up on my page as a link. For this to work, is my Twig correct?
I have searched the web, Grav docs, these forums, Grav logs, and even asked ChatGPT but have not found an answer yet.
Thanks for your help.
YAML:
title: position
'@extends':
type: default
context: blueprints://pages
form:
fields:
tabs:
type: tabs
active: 1
fields:
content:
fields:
content:
type: tinymce
label: Content
validate:
type: textarea
header.rightPane:
type: tinymce
label: Right Pane
header.media_order:
type: pagemedia
label: PLUGIN_ADMIN.PAGE_MEDIA
header.sideLinks:
name: sideLinks
type: list
label: Links
style: vertical
soft: true
fields:
.title:
type: text
label: Title
.linktype:
type: elements
label: Link Type
default: pageField
options:
pageField: Page
externalLinkField: External Link
mediaField: Media Upload
fields:
pageField:
type: element
fields:
.page:
name: page
type: pages
label: Page
externalLinkField:
type: element
name: externalLinkField
fields:
.link:
name: link
type: text
label: External Link
mediaField:
type: element
fields:
mediaField.media:
type: filepicker
folder: '@self'
preview_images: true
label: Media Upload
order:
type: hidden
default: 1
header.linkPlacement:
type: toggle
label: Link Placement
highlight: side
default: side
options:
side: On the left side
bottom: On the bottom
classes: fancy
size: large
header.enableRightPane:
type: toggle
label: Enable Right Pane
highlight: yes
default: yes
options:
yes: Yes
no: No
classes: fancy
size: large
Twig (unrelated parts omitted):
{% for link in page.header.sideLinks %}
{% if link.linktype == "pageField" %}
<a href="{{ link.pageField.page }}">
<div class="side-link-bottom-placement" >
<img class="link-icon" src="{{ url('theme://img/link.png') }}" />
{{ link.title }}
</div>
</a>
{% endif %}
{% if link.linktype == "externalLinkField" %}
<a href="https://{{ link.externalLinkField.link }}">
<div class="side-link-bottom-placement" >
<img class="link-icon" src="{{ url('theme://img/link.png') }}" />
{{ link.title }}
</div>
</a>
{% endif %}
{% if link.linktype == "mediaField" %}
<a href="{{ page.url }}/{{ link.mediaField.media }}">
<div class="side-link-bottom-placement" >
<img class="link-icon" src="{{ url('theme://img/attachment.png') }}" />
{{ link.title }}
</div>
</a>
{% endif %}
{% endfor %}