Page 1 of 1

LISE and Custom Field from UDT

Posted: Thu Sep 29, 2016 10:29 pm
by clapczyn
Hi, I'm trying to use the "Custom Field from UDT" fielddef in LISE but I just can't get it to work.

So I've got a UDT that just reads out all directories and files in a given directory:

Code: Select all

if ($fh = opendir('uploads/mydir/')) {
while (false !== ($entry = readdir($fh))) {
  if ($entry != "." && $entry != "..") {
    $files[] = $entry; 
  }
}
closedir($fh);
}
return $files;
this should populate the dropdown but it just doesn't. As far as I understand it the UDT should return an array which it does.

I'm pretty sure I'm missing something really simple, but I just don't see it.
I'm thankful for any help …

Stefan

Re: LISE and Custom Field from UDT

Posted: Fri Sep 30, 2016 12:16 pm
by velden
It's not that hard to debug this UDT itself. Did you check the output before using it in LISE?

Code: Select all

if ($fh = opendir('uploads/mydir/')) {
I'd suspect this very first line returns false. Often those relative paths don't work as you don't know the current working directory.

Re: LISE and Custom Field from UDT

Posted: Fri Sep 30, 2016 12:48 pm
by clapczyn
nope, UDT works just fine – returns this array:

Array ( [0] => folder_a [1] => folder_b [2] => folder_c [3] => folder_d ) 1

Re: LISE and Custom Field from UDT

Posted: Fri Sep 30, 2016 1:01 pm
by Jo Morg
LISE template expects an associative array in order to be able to point to a selected value when it exists. What you can do is change this line:

Code: Select all

/*****/
$files[] = $entry;
/** change to **/
$files[$entry] = $entry;
/*****/
 

Re: LISE and Custom Field from UDT

Posted: Fri Sep 30, 2016 10:08 pm
by clapczyn
Hi,

looks like both answers were correct and I'm an idiot ;D :-X

1. yes, the field requires an associative array as a return value ::)
2. also the filepath was wrong:
I tested the tag in the template where the relative path worked just fine. But when the UDT is called from the field definition it seems the script is included somewhere else ?! the relative path wasn't working anymore so i had to use root-path/my_relative_path to get to where I wanted to be …

anyway, thx a lot for your help and thx for this great module ;)