bernhard Posted September 27, 2018 Share Posted September 27, 2018 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 More sharing options...
BitPoet Posted September 27, 2018 Share Posted September 27, 2018 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. 1 1 Link to comment Share on other sites More sharing options...
bernhard Posted September 27, 2018 Author Share Posted September 27, 2018 Looks like this is exactly what I need! The image part was only the icing on the cake and can wait ? Thank you! Link to comment Share on other sites More sharing options...
Robin S Posted September 27, 2018 Share Posted September 27, 2018 There is also this: https://modules.processwire.com/modules/fieldtype-select-file/ 2 Link to comment Share on other sites More sharing options...
bernhard Posted September 27, 2018 Author Share Posted September 27, 2018 Thx, that was the first module I found, but I thought it is only for selecting a file to be used as template. Didn't read carefully enough that this is just an OPTION. Thx! I'll try this module first ? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now