Hide image with specific template in media galley

My question;
is it possible to hide a file with a specific template in my media gallery on a page?

Situation:
I have a page called Work with subpages called Projects and on each project page I have a media gallery which contains both images and videos ( I would like the image and video to be in the same section so I can arrange the order as I see fit )

When I add a new file to the media gallery it will assign either a image or video blueprint which I have set up in the hook file.create:after

The reason I do it on the hook is that I also have a file upload on the video that takes an image which I use as poster for the video. It will assign a blueprint called poster.yml if the image file contains ‘-poster’:

'hooks' => [
        'file.create:after' => function (Kirby\Cms\File $file) {

            function containsPoster($filename)
            {
                return strpos($filename, "-poster") !== false;
            }

            if (containsPoster($file)) {
                $file = $file->update([
                    'template' => 'poster',
                ]);
            } else {
                $file = $file->update([
                    'template' => $file->type(),
                ]);
            }
        }
    ]

The poster image is used both on the front end ( html video ) and also as a preview image for the video file so it’s not left with an icon.

The video.yml blueprint looks as following:

image:
  type: query
  query: file.videoCoverPhoto.toFile
  ratio: 5/4
  cover: true

And the poster videoCoverPhoto on the video.yml looks like:

videoCoverPhoto:
            type: files
            layout: list
            label: Video poster
            size: tiny
            uploads:
              template: poster
            max: 1

I’m not sure if this is the best way to do it as it seems a bit tacky to manage videos like such.

Any suggestions or hints would be greatly appreciated.

Kirby: 4.1.0
PHP: 8.3.3
Browser: Safari 17.3
OS: Mac 14.3

Hm, I guess the question is in the topic title, but where is the problem now? You can filter by template on the frontend now?

This seems to be in one file (video.yml), but I don’t understand how these two parts relate. Would have been better to post the complete blueprint, if this information is needed to understand the problem.

Here’s the full video.yml blueprint:

title: Video

accept:
  type: video

# set focus to false for video files.
focus: false

image:
  type: query
  query: file.videoCoverPhoto.toFile
  ratio: 5/4
  cover: true

columns:
  - width: 1/3
    sections:
      information:
        type: fields
        fields:
          videoDescription:
            label: Video description
            type: text
          caption:
            label: Video caption
            type: textarea
            buttons: false
            placeholder: caption for video
          videoCoverPhoto:
            type: files
            layout: list
            label: Video poster
            size: tiny
            uploads:
              template: poster
            max: 1

  - width: 1/3
    sections:
      meta:
        type: fields
        fields:
          license:
            label: License
            help: Include license meta data for the image.
            width: 1/2
            type: toggle
            default: true
            text:
              - "no"
              - "yes"
          copyright:
            label: Copyright
            help: Include copyright meta data for the image.
            width: 1/2
            type: toggle
            default: true
            text:
              - "no"
              - "yes"
          videoDurationHours:
            label: "Hours:"
            help: "hours"
            width: 1/3
            type: time
            display: HH
          videoDurationMinutes:
            label: "Minutes:"
            help: ""
            width: 1/3
            type: time
            display: mm
          videoDurationSeconds:
            label: "Seconds:"
            help: ""
            width: 1/3
            type: time
            display: ss
          videoUploadDate:
            label: upload date
            type: date
          videoWidth:
            label: video width
            type: number
            width: 1/2
          videoHeight:
            label: video height
            type: number
            width: 1/2
          toggleLoopable:
            label: Is the video loopable?
            type: toggle
            default: true
            text:
              - "no"
              - "yes"
  - width: 1/3
    sections:
      color:
        type: fields
        fields:
          videoForgroundColor:
            type: color
            label: Image forground color
            help: Pick a destinct forground color from the image
          videoBackgroundColorFrom:
            type: color
            label: Image background color
            help: Pick a destinct background color from the image
          videoBackgroundColorTo:
            type: color
            label: Image background color
            help: Pick a destinct background color from the image

What I am trying to do its assign an image to the video which function as both a poster for the front end but also as a preview image so I can easily see what video file I moving around.

Here is a screenshot of how it looks now in the project page’s media gallery:

and here’s how I assign the poster through the video blueprint:

Not sure if that makes sense but let me know if I need to clarify further!
thank you.

You can now filter a files section (provided you are on Kirby 4) with a query, so you can exclude those poster images by template.

LEDGEND !!! :slight_smile: thank you
A query of:

query: page.files.not(page.files.template("poster"))

did the trick :slight_smile:

@texnixe - one followup question as I did the query in the files section I lost the ability to drag/drop sort the media - I added in the:

sortable: true

but that made no difference. Here is the full blueprint:

# page title
title: Project

# options for when creating a new work projects
create:
  title: "{{ page.client }} – {{ page.project }}"
  fields:
    - client
    - project
  slug: "{{ page.client }}-{{ page.project }}"

# options for available status options
status:
  listed: Published
  draft: Draft
  unlisted: Unlisted

columns:
  media:
    width: 2/3
    sections:
      photoGallery:
        type: files
        layout: cards
        size: medium
        label: Media
        # kirby.collection("some-collection").not(kirby.collection("excluded-collection"))
        # query: page.files.template("video")
        query: page.files.not(page.files.template("poster"))
        sortable: true
        # template: image
        info: "{{ file.template }}"
      fields:
        fields:
          lineA:
            type: line
          toggleVideoContent:
            label: Project contains video
            type: toggle
            default: "no"
            text:
              - "no"
              - "yes"
          videoGallery:
            type: files
            layout: cards
            size: tiny
            info: "{{ file.template }}"
            label: Videos
            uploads: video
            when:
              toggleVideoContent: true
          toggleVideoCover:
            label: Use project video cover
            type: toggle
            default: "no"
            options:
              no:
                en: "no"
                dk: "nej"
              yes:
                en: "yes"
                dk: "ja"
          projectVideoCover:
            type: files
            layout: cards
            size: tiny
            uploads: video
            info: "{{ file.template }}"
            max: 1
            label: Project video cover
            when:
              toggleVideoCover: true

  information:
    width: 1/3
    sections:
      meta:
        type: fields
        fields:
          client:
            label: client name
            type: select
            required: true
            placeholder: select client
            help: Select client for project, or create new under Work > Settings
            options:
              type: query
              query: site.find("work").clients.toStructure
              text: "{{ item.clientname }}"
              value: "{{ item.clientname }}"
          project:
            label: project name
            type: text
            required: true
          tags:
            type: tags
            label: Categories
            min: 1
            accept: options
            help: Select one or more categories for the project, or create new under Work > Settings
            options:
              type: query
              query: site.find("work").categories.toStructure
              text: "{{ item.category }}"
              value: "{{ item.category }}"
          lineB:
            type: line
          description:
            type: textarea
            size: small
            buttons: false
          toggleDisplayDescription:
            label: Hide description on project page?
            type: toggle
            default: "no"
            options:
              - no
              - yes
          lineC:
            type: line
          credits:
            label: Credit list
            type: structure
            fields:
              name:
                label: name
                type: text
              role:
                label: role
                type: text
              link:
                label: link
                type: url

Yes, when using a query, you cannot sort manually anymore, that’s the downside.

The only way out of this dilemma would be to:

  1. assign the same blueprint to all files that should be in the section, while moving the posters to a separate section. Downside: You would have to use conditions in your file blueprint to show video fields for videos and image fields for images.

or

  1. Use separate sections per file type and add an additional files field where you would select and sort manually the files you want to see in the gallery.
1 Like

argh that’s a bit of a stick in the gear.
Thank you for clearing it up!

See added information above.

thanks for the suggestions - option 2 seems like the way to go because I will likely also need to upload 3D and Audio files for projects :slight_smile:

Hi @texnixe thanks for the suggestions. I went with the second option and it’s now all working.
For anyone else looking for a similar solution here’s the blueprint:

#
# Blueprint for Projects
#
# page title
title: Project

# options for when creating a new work projects
create:
  title: "{{ page.client }} – {{ page.project }}"
  fields:
    - client
    - project
  slug: "{{ page.client }}-{{ page.project }}"

# options for available status options
status:
  listed: Published
  draft: Draft
  unlisted: Unlisted

#
# Content
#
tabs:
  #
  # TAB 1 - content
  #
  content:
    label: Content
    icon: text
    columns:
      # layout
      media:
        width: 1/2
        fields:
          #
          # Project - media
          #
          mediaGallery:
            type: files
            layout: cards
            size: medium
            label: Project Media
            uploads: false
            help: select media, to upload see storage tab.
            sortable: true
            info: "{{ file.template }}"
      #
      # Project - information
      #
      information:
        width: 1/2
        fields:
          #
          # Project - client
          #
          client:
            label: Project client
            width: 1/2
            type: select
            required: true
            placeholder: select client
            help: Select client for project, or create new under Work > Settings
            options:
              type: query
              query: site.find("work").clients.toStructure
              text: "{{ item.clientname }}"
              value: "{{ item.clientname }}"
          #
          # Project - title
          #
          project:
            label: project title
            width: 1/2
            type: text
            help: Enter the project name
            required: true
          # break
          lineA:
            type: line
          #
          # Project - categories
          #
          tags:
            type: tags
            label: Categories
            min: 1
            accept: options
            help: Select one or more categories for the project, or create new under Work > Settings
            options:
              type: query
              query: site.find("work").categories.toStructure
              text: "{{ item.category }}"
              value: "{{ item.category }}"
          # break
          lineB:
            type: line
          #
          # Project - description
          #
          description:
            type: textarea
            size: small
            buttons: false
          toggleDisplayDescription:
            label: Hide description on project page?
            type: toggle
            help: Hide the description on the project page but will keep it for SEO.
            default: "no"
            options:
              - no
              - yes
          # break
          lineC:
            type: line
          #
          # Project - credit list
          #
          credits:
            label: Credit list
            type: structure
            fields:
              name:
                label: name
                type: text
              role:
                label: role
                type: text
              link:
                label: link
                type: url

  #
  # TAB 2 - media storage
  #
  storage:
    label: Media
    icon: import
    fields:
      #
      # Media - Image uploading section
      #
      imageMedia:
        label: Image upload
        help: Upload project images here.
        type: files
        layout: cards
        size: medium
        uploads: image
        info: "{{ file.template }}"
      # break
      lineD:
        type: line
      #
      # Media - Video uploading section
      #
      videoMedia:
        label: Video upload
        help: Upload project videos here.
        type: files
        layout: cards
        size: medium
        uploads: video
        info: "{{ file.template }}"
      # break
      lineF:
        type: line
      #
      # Media - Audio uploading section
      #
      audioMedia:
        label: Audio upload
        help: Upload project audio here.
        type: files
        layout: cards
        size: medium
        uploads: audio
        info: "{{ file.template }}"