Page 1 of 1

directory listing like content image tag

Posted: Wed Oct 13, 2010 8:40 am
by haapati
Is there way to get a dropdown menu in content editing where you could choose a specific directory and it would return the directory path in the page template?

Just like the content image tag but instead of picture files it shows just a directory list.

I think I would get the dropdown menu like that if I would edit the code of Content.inc.php. But is there any way to do that without editing the CMSMS Core files?

Re: directory listing like content image tag

Posted: Wed Oct 13, 2010 7:10 pm
by NaN
I just posted here a possible solution to select multiple images using AdvancedContent and GBFilePicker and a UDT.
This can also be used to list directories only.

Code: Select all


$dir = '';
if(isset($params['dir']))
{
	$dir = $params['dir'];
}
$display = 'filename';
if(isset($params['display']))
{
	$display = $params['display'];
}
$output = array();
if($GBFilePicker =& cmsms()->modules['GBFilePicker']['object'])
{
	$files =& $GBFilePicker->GetFiles($dir); // dir relative to the uploads dir
	foreach($files as $onefile)
	{
		if(!onefile->is_dir) continue;

		switch($display)
		{
			case 'relurl':
				$output[] = $onefile->relurl; // this will be the url of the dir relative to the uploads dir (e.g.: images/)
				break;
			case 'fullurl':
				$output[] = $onefile->fullurl; // this will be the full url to the directory (e.g.: yourdomain/uploads/images/)
				break;
			case 'filename':
			default:
				$output[] = $onefile->basename; // this will be the dirname only (e.g.: images)
				break;
		}
	}
}
$_output = implode("|",$output); // this will stick the dirnames together separated by a pipe
echo $_output;

with AdvancedContent you now can create a dropdown or a multi select list in your template to be used in backend:

Code: Select all


{content block="dirs" label="Select a directory" block_type="dropdown" items=":::list_dirs:::" values=":::list_dirs display='relurl':::" smarty=true}

This should print out a dropdown with dirs only.