Skip to content

Commit

Permalink
Adds absoluteThemeResourceURL global template variable to ThemeResour…
Browse files Browse the repository at this point in the history
…ceHelper.php, useful for templates where an absolute url is needed eg. emails.
  • Loading branch information
k-coidan committed Jul 19, 2024
1 parent 2bc2483 commit 5194376
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/src/View/ThemeResourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\View;

use SilverStripe\Control\Director;
use SilverStripe\Core\Manifest\ModuleResourceLoader;
use SilverStripe\View\TemplateGlobalProvider;
use SilverStripe\View\ThemeResourceLoader;
Expand All @@ -23,11 +24,22 @@ public static function themeResourceURL(string $resource): ?string
return ModuleResourceLoader::singleton()->resolveURL($path);
}

public static function absoluteThemeResourceURL(string $resource): ?string
{
$url = static::themeResourceURL($resource);
if (!$url) {
return '';
}

return Director::absoluteURL($url);
}

public static function get_template_global_variables(): array
{
return [
'themeResourcePath',
'themeResourceURL'
'themeResourceURL',
'absoluteThemeResourceURL',
];
}
}

0 comments on commit 5194376

Please sign in to comment.