Show field in blueprint depending on file type

Is this possible? :thinking:

If you upload an image or a video with the same field they will share the same template (if I’m not wrong). Clicking on the file will take you to the template blueprint and it would be cool to show fields depending on file type. Alt text for images and other settings for video.

If this doesn’t work I need to have two different upload fields with two different file templates (image and video). Or if anyone have a better solution I’m interested :slight_smile:

1 Like

Maybe assign a different template based on file type via a hook?

Is this going in the right direction? How do I assign a template? Not sure changeTemplate is the way to go…

'file.create:after' => function ($file) {
  if ($file->type() == 'video') {
    $file->changeTemplate('video');
  }
}

You would do that with the $file->update() method.

1 Like

Awesome! Working now :+1:

I use the following but now uploading an avatar to a user profile no longer works :thinking:

How can I skip this for user avatar uploads?

'file.create:after' => function($file) {
  if ($file->type() === 'image') {
    $file->update([
      'Alt'      => '',
      'Caption'  => '',
      'Template' => 'image'
    ]);
  } elseif ($file->type() === 'video') {
    $file->update([
      'Caption'     => '',
      'Autoplay'    => 'true',
      'Controls'    => 'true',
      'Loop'        => 'true',
      'Muted'       => 'true',
      'Playsinline' => 'false',
      'Template'    => 'video'
    ]);
  }
}
1 Like

Adding && $file->template() !== 'avatar' fixed the issue:

if ($file->type() === 'image' && $file->template() !== 'avatar')
1 Like