smarty icon indicating copy to clipboard operation
smarty copied to clipboard

date_format: check if already exists

Open kornrunner opened this issue 2 years ago • 3 comments

Since everything in libs/ gets autoloaded by composer - there's no easy way to override built-in modifiers.

This is an attempt at a workaround for date_format specifically, as seen within smarty_mb_str_replace

kornrunner avatar Sep 12 '23 07:09 kornrunner

Since everything in libs/ gets autoloaded by composer

Is that true? I don't think that's true. My project has Smarty modifiers and functions overridden. Smarty loads those files on demand, not always by Composer. Just add a plugins_dir before Smarty's and that's where Smarty will look first.

	$smarty->plugins_dir = [
		PROJECT_INC_SMARTY . '/plugins', // Mine
		PROJECT_VENDOR . '/smarty/smarty/libs/plugins', // Smarty's built-in
	];

rudiedirkx avatar Sep 12 '23 09:09 rudiedirkx

Since everything in libs/ gets autoloaded by composer

Is that true? I don't think that's true. My project has Smarty modifiers and functions overridden. Smarty loads those files on demand, not always by Composer. Just add a plugins_dir before Smarty's and that's where Smarty will look first.

Specified within: https://github.com/smarty-php/smarty/blob/support/4.3/composer.json#L35-L38

	$smarty->plugins_dir = [
		PROJECT_INC_SMARTY . '/plugins', // Mine
		PROJECT_VENDOR . '/smarty/smarty/libs/plugins', // Smarty's built-in
	];

That's what I was using, but I get compile errors for using already declared function (because autoloader loaded the Smarty file, even before use).

kornrunner avatar Sep 12 '23 09:09 kornrunner

Specified within: https://github.com/smarty-php/smarty/blob/support/4.3/composer.json#L35-L38

That's a class map, not functions. Functions aren't autoloaded. Maybe something else includes that file twice. Or a smarty/plugin cache. Or something. I've never had a problem with this. Buuut I have no idea which version I'm running. It would be very weird if this had changed on purpose.

rudiedirkx avatar Sep 12 '23 12:09 rudiedirkx