mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Added |replace_last(search, replace) filter
This commit is contained in:
parent
010753bdd6
commit
c08341046b
|
|
@ -1,6 +1,8 @@
|
|||
# v1.7.32
|
||||
## mm/dd/2022
|
||||
|
||||
1. [](#new)
|
||||
* Added `|replace_last(search, replace)` filter
|
||||
1. [](#improved)
|
||||
* Added multi-language support for page routes in `Utils::url()`
|
||||
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
|
|||
new TwigFilter('yaml_encode', [$this, 'yamlEncodeFilter']),
|
||||
new TwigFilter('yaml_decode', [$this, 'yamlDecodeFilter']),
|
||||
new TwigFilter('nicecron', [$this, 'niceCronFilter']),
|
||||
new TwigFilter('replace_last', [$this, 'replaceLastFilter']),
|
||||
|
||||
// Translations
|
||||
new TwigFilter('t', [$this, 'translate'], ['needs_environment' => true]),
|
||||
|
|
@ -547,6 +548,21 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
|
|||
return $cron->getText('en');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @param $search
|
||||
* @param $replace
|
||||
* @return string|mixed
|
||||
*/
|
||||
public function replaceLastFilter($str, $search, $replace)
|
||||
{
|
||||
if (is_string($str) && ($pos = mb_strrpos($str, $search)) !== false) {
|
||||
$str = substr_replace($str, $replace, $pos, mb_strlen($search));
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Cron object for a crontab 'at' format
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user