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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

A Way to Override Page Media Field within Custom Blueprint or Route media to custom folder?

admin first-time form

Started by Cedric W 8 years ago · 7 replies · 2354 views
8 years ago

Is there a way to override the Page Media field in the admin or change the destination of the file being uploaded? By default I see the the media file is uploaded to the pages folder, but is there a way to change where the image is uploaded to? If its not possible to route the files from the default page media, is there a way to hide the default page media upload field so I can use a custom upload field in my custom blueprint?

last edited 03/05/18 by Cedric W
8 years ago

Hi horussky:

To complete dmitri response, you can remove the page media field (named header.media_order) by writing:

YAML
title: Artistes
'@extends':
    type: default
    context: blueprints://pages

form:
  fields:
    tabs:
      fields:
        content:
          fields:
              content:
                unset@: true
              header.media_order:
                unset@: true
👍 3
8 years ago

Thanks @dimitrilongo and @paul

unset worked like a charm.

8 years ago

@paul or @dimitrilongo

So now I have my custom upload field working. It's uploading to the correct file folder. Now I'm trying to pull the image file from the folder on the front end and it seems different than trying to pull from the page media field or say a text field. Am I doing something wrong?

Blueprint

YAML
header.overview.pagemedia:
     type: file
     name: event_image
     label: Event Image
     multiple: false
     destination: 'theme@:/images'
     random_name: false
     avoid_overwriting: false
     style: vertical
     accept:
         - 'image/*'

Front End

{% for image in header.overview.pagemedia %}
<div class="topcontent" style="background-image: url({{ image.url }})"></div>
{% endfor %}

last edited 03/05/18 by Cedric W
8 years ago

hi @horussky

you can try

TWIG

{% for key,val in page.header.overview.pagemedia %}
   {% set myimagepath = '/' ~ val.path %}
   <div class="topcontent" style="background-image: url({{ myimagepath }})"></div>
{% endfor %}

try to dump to see how the array is :
{{dump(page.header.overview.pagemedia)}}

You can try to use also filepicker or one i like Media picker Field
Many ways, thanks to Grav ;-)

Hope that helps

8 years ago

@dimitrilongo

This worked for me.

{% for image in header.overview.page_cta %}
{% set myimagepath = '/' ~ image.path %}
<div class="topcontent" style="background-image: url({{ myimagepath }})"></div>
{% endfor %}

Thanks for the help. I may still check out the Media Picker Field just to see which method I feel more comfortable with. But I think this scenario could be a possible recipe on the doc.

last edited 03/06/18 by Cedric W

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1136 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 134 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 129 7 months ago