I just write an extension for dbtext amd inject it
Useful for things like $Mystring.YoutubeID
The following is a snippet of such in SS4:
/* yml */
SilverStripe\ORM\FieldType\DBString:
extensions:
- \CustomText
/* CustomText.php */
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataExtension;
class \CustomText extends DataExtension {
public function ReplaceYoutubeID($ID) {
$url = $this->owner->value;
$pattern =
'%^# Match any youtube URL. use delimiter percent instead of default / so no need to escape
(?:https?://)? # Optional scheme. Either http or https
(?:www\.)? # Optional www subdomain
(?: # Group host alternatives
youtu\.be/ # Either youtu.be,
| youtube\.com # or youtube.com
(?: # Group path alternatives
/embed/ # Either /embed/
| /v/ # or /v/
| /watch\?v= # or /watch\?v=
) # End path alternatives.
) # End host alternatives.
([\w-]{10,12}) # Allow 10-12 for 11 char youtube id.
$%x'
; // x modifier - ignores white space; ?: in parenthesis - non-capturing group
$result = preg_match($pattern, $url, $matches);
if (false !== $result && isset($matches[1])) {
return str_replace($matches[1], $ID, $url);
}
// no match
return $url;
}
}
/* .ss */
<% loop $Videos %>
$YoutubeLink : $YoutubeLink.ReplaceYoutubeID($ID)
<% end_loop %>
/* results */
https://www.youtube.com/watch?v=IesIsKMjB4Y : https://www.youtube.com/watch?v=2
So yes, passing parameters work