Jump to content

Recommended Posts

Posted

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 ? 

Posted

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
Posted

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 ?

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
  • Recently Browsing   0 members

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