presprog/kirby-auto-file-templates 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

presprog/kirby-auto-file-templates

Composer 安装命令:

composer require presprog/kirby-auto-file-templates

包简介

Automatically assign file templates on upload based on the file type

README 文档

README

Kirby Auto File Templates Plugin

Automatically assign templates to your uploaded files

⚡ Ready for Kirby 5!

This plugin automatically assigns file templates to your uploaded files, based on the respective file type. This way it does not matter, which file type you upload from which field or section – the template assigned will always be the same. This is especially handy, when you use a single files section per page, that stores all the different file types used on the page.

Important

Requires at least Kirby 4.0 and PHP 8.2

🚀 How to use

Set up your configuration (see next section) first. The plugin will then run after each uploaded file (file.create:after hook) and assign the configured template automatically.

If you add the plugin to an existing project, you can run the auto-templates command from the CLI. It will iterate over every file in every page and assign the template according to the configuration:

$ php vendor/bin/kirby auto-templates

image.png: image
video.mp4: video

> All files updated

By default, existing template assignments will not be touched. To change that, run the command with --force/-f or set the forceOverwrite option globally in your config.php (see below).

⚙️ Config

The plugin works in an opt-in manner: It does nothing except you tell it to.

// site/config/config.php

'presprog.auto-file-templates' => [
  // Do nothing (default)
  'autoAssign' => false,

  // OR automatically assign a file template for every file type
  'autoAssign' => true,

  // OR only assign templates to some file types (ignore file types other than `image` and `video`
  'autoAssign' => [
      'image' => true,
      'video' => true,
  ],

  // OR define a specific template for just some file types and let the plugin decide for the others
  'autoAssign' => [
      'image' => 'my-custom-image-blueprint',
      'video' => true, // => 'video'
  ],

  // OR handle more advanced use-cases in callable yourself (assign different file templates for vector and raster images)
  'autoAssign' => [
      'image' => function(\Kirby\Cms\File $file) {
          return match (F::extension($file->filename())) {
              'svg'   => 'vector',
              default => 'image',
          };
      },
  ],

  // Overwrite existing template assignments (default: false)
  'forceOverwrite' => true,
],

With autoAssign = true, each file type will get the identically named file blueprint assigned as template:

File type File blueprint
audio site/blueprints/files/audio
archive site/blueprints/files/archive
code site/blueprints/files/code
image site/blueprints/files/image
video site/blueprints/files/video
your-type site/blueprints/files/your-type

* The Kirby core file types archive, audio, document, image and video and your custom file type extensions are supported out-of-the-box.

💻 How to install

Install this plugin via Composer (recommended):

composer require presprog/kirby-auto-file-templates

Or download the ZIP file from GitHub and unpack it to site/plugins/kirby-auto-file-templates

Or as Git submodule

git submodule add https://github.com/presprog/kirby-auto-file-templates.git site/plugins/auto-file-templates

✅ To do

  • Add multi-language support

📄 License

MIT License Copyright © 2025 Present Progressive

Made by Present Progressive for the Kirby community.

presprog/kirby-auto-file-templates 适用场景与选型建议

presprog/kirby-auto-file-templates 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 569 次下载、GitHub Stars 达 9, 最近一次更新时间为 2024 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 presprog/kirby-auto-file-templates 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 presprog/kirby-auto-file-templates 我们能提供哪些服务?
定制开发 / 二次开发

基于 presprog/kirby-auto-file-templates 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 569
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 16
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-19