diff --git a/src/opnsense/mvc/app/config/services.php b/src/opnsense/mvc/app/config/services.php index 4395400a8..15c8bb68c 100644 --- a/src/opnsense/mvc/app/config/services.php +++ b/src/opnsense/mvc/app/config/services.php @@ -9,6 +9,26 @@ use Phalcon\Session\Adapter\Files as SessionAdapter; use OPNsense\Core\Config; use OPNsense\Core\Routing; +/** + * search for a themed filename or return distribution standard + * @param string $url relative url + * @param array $theme theme name + * @return string + */ +function view_fetch_themed_filename($url, $theme) { + $search_pattern = array( + "/themes/{$theme}/build/", + "/" + ); + foreach ($search_pattern as $pattern) { + $filename = "/usr/local/opnsense/www{$pattern}{$url}"; + if (file_exists($filename)) { + return str_replace("//", "/", "/ui{$pattern}{$url}"); + } + } + return $url; // not found, return source +} + /** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ @@ -43,11 +63,7 @@ $di->set('view', function () use ($config) { 'compiledSeparator' => '_' )); // register additional volt template functions - $volt->getCompiler()->addFunction('javascript_include_when_exists', function ($local_url) { - $chk_path = "str_replace('/ui/','/usr/local/opnsense/www/',".$local_url.")"; - $js_tag = "''"; - return "file_exists(".$chk_path.") ? ".$js_tag." :''"; - }); + $volt->getCompiler()->addFunction('theme_file_or_default', view_fetch_themed_filename); return $volt; }, diff --git a/src/opnsense/mvc/app/views/layouts/default.volt b/src/opnsense/mvc/app/views/layouts/default.volt index 21a5dc005..ffd60fdf5 100644 --- a/src/opnsense/mvc/app/views/layouts/default.volt +++ b/src/opnsense/mvc/app/views/layouts/default.volt @@ -236,8 +236,7 @@ - {{javascript_include_when_exists('/ui/themes/' ~ theme_name ~ '/build/js/theme.js')}} - +