Added has_env() twig function to test if environmental variable is defined

This commit is contained in:
Matias Griese
2022-04-01 21:52:26 +03:00
parent 17d4796def
commit 258d7473bc
2 changed files with 11 additions and 0 deletions

View File

@@ -4,6 +4,7 @@
1. [](#new)
* Added `FileInterface::touch()` method
* Added optional `$field` parameter to `FlexMediaTrait::deleteMediaFile()` method
* Added `has_env()` twig function to test if environmental variable is defined
2. [](#improved)
* By default, add media to only pages which have been initialized in pages loop
3. [](#bugfix)

View File

@@ -222,6 +222,7 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
new TwigFunction('svg_image', [$this, 'svgImageFunction']),
new TwigFunction('xss', [$this, 'xssFunc']),
new TwigFunction('unique_id', [$this, 'uniqueId']),
new TwigFunction('has_env', [$this, 'hasEnv']),
// Translations
new TwigFunction('t', [$this, 'translate'], ['needs_environment' => true]),
@@ -707,6 +708,15 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
return Utils::uniqueId($length, $options);
}
/**
* @param $string
* @return bool
*/
public function hasEnv($string): bool
{
return is_string($string) && getenv($string) !== false;
}
/**
* @param string $string
* @return string