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.

General

Use random Name in pagemedia

Started by David 5 years ago · 2 replies · 645 views
5 years ago

I want to use the pagemedia field for a gallery and for reasons I want to use random_name: true but this doesn't work

5 years ago

The pagemedia field is located in the admin area under the content editor. There you can upload and order images for your post. It’s coming with gravs admin plugin.
The random_name is an option you can enable on file upload fields, when creating your own forms with blueprints. More details can be found here: How to: Add a file upload | Grav Documentation
When creating a file upload field, I can enable the random_name property and all uploaded files get a random filename. But I see no option to enable random file names on this default field.
I tried different approaches my last one including defining my own blueprint which overrides the default field. Like shown below, but the pagemedia field does not have an option for random file names. Any suggestions?

YAML
title: Fotos
@extends’:
type: default
context: blueprints://pages

form:
  fields:
    tabs:
      fields:
        content:
          fields:
            header.media_order:
              replace@: true
              type: pagemedia
              label: PLUGIN_ADMIN.PAGE_MEDIA
                random_name: true
5 years ago

Hi @redstone
I don't know about the random name function but a workaround might be if you use the built in Grav cache as the cache gives them random names as part of its processing. You won't see the name in the admin panel - only on the output. One way to use the cache is to name your files to include '@2x' before you upload them - see here https://learn.getgrav.org/16/content/media#higher-density-displays

EDIT: I think I'm only partially correct - using @2x does change the file name but only partially, it adds a random set of characters to your existing filename so only partially random and probably not what you're looking for.

last edited 01/14/21 by Ptarmic

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 85 13 hours ago
General · by pamtbaau, 18 hours ago
1 60 18 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 350 5 days ago
General · by Duc , 6 days ago
3 44 5 days ago