Skip to content

Commit

Permalink
feat: template globals (fixes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Sep 11, 2023
1 parent 3672c17 commit 34c29ff
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/HashPathExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

use SilverStripe\Core\Extension;
use SilverStripe\View\SSViewer;
use SilverStripe\View\TemplateGlobalProvider;

/**
* Class HashPathExtension
*/
class HashPathExtension extends Extension
class HashPathExtension extends Extension implements TemplateGlobalProvider
{
/**
* The format of the web path
* @var string
*/
protected static $format = '%s/%s.v%s.%s';

/**
* Whether or not to output links as relative
* @var boolean
Expand Down Expand Up @@ -103,4 +105,27 @@ protected function getPath($path, $theme = true)

return BASE_PATH . $path;
}


public static function generateHashFile($path, $theme = true)
{
$hashPath = new HashPathExtension();
return $hashPath->HashFile($path, $theme);
}


public static function generateHashPath($path, $theme = true)
{
$hashPath = new HashPathExtension();
return $hashPath->HashPath($path, $theme);
}


public static function get_template_global_variables()
{
return [
'HashFile' => 'generateHashFile',
'HashPath' => 'generateHashPath'
];
}
}

0 comments on commit 34c29ff

Please sign in to comment.