Jump to content

File Picker Fieldtype?


bernhard
 Share

Recommended Posts

Is there a module to pick a file from a given directory? I want to pick a template for creating a PDF invoice and thought it would be nice to have the option to choose from different templates located in a folder somewhere in the sites folder.

It's not hard to add a field to the edit form, but if there's already a ready solution for that I'd prefer that of course. I'd also combine it with a preview like I did on my first module: 

 If nobody knows of an existing solution I'll go ahead and build one ? 

Link to comment
Share on other sites

Perhaps FieldtypeDropdownDynamic might be worth a look. It shouldn't be hard to enhance it with an image picker like you're doing in your module. It lets you define PHP code to fill PW select fields.

Just install the module, then create a PHP file somewhere under site/templates that builds your selection:

<?php namespace ProcessWire;

# this is site/templates/selections/intranetforms.php

$opts = [];

foreach(scandir($config->paths->templates . "IntranetForms") as $d) {
	if(substr(strtolower($d), -4) != '.tpl') continue;
	$name = preg_replace('/\.tpl$/i', '', $d);
	$opts[] = array("label" => $name, "value" => $name);
}

return $opts;

Then add a field of this type, enter the relative (to site/templates/) path to the PHP and make sure to check the filename option before saving.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...