Dropdown with theme files

Hi! Is there a way to use all .htm files from the theme folder /themes/default/partials/svg/ as dropdown field options? The saved value should be the name of the file, e.g.: ‘lorem-ispum.htm’

you can use dropdown field and then create a method, that will fill data from current theme.

use Cms\Classes\Theme;
$theme = Theme::getActiveTheme();
$theme_path = $theme->getPath();

and then you can use glob or something, to gain array of all files in theme_path, etc.

1 Like

@snipi thank you! I used glob:

use Cms\Classes\Theme;
use File;

$theme =  Theme::getActiveTheme();
$theme_path = $theme->getPath();

$keys = [];
$values = [];

foreach (File::glob($theme_path . '/partials/svg/*.htm*') as $file) {
    array_push($keys, basename($file));
    array_push($values, basename($file));
$options = array_combine($keys, $values);

return $options;

yup, correct :wink: glad to help

1 Like