smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.24k stars 705 forks source link

date_format: check if already exists #902

Open kornrunner opened 12 months ago

kornrunner commented 12 months ago

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

rudiedirkx commented 12 months ago

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
    ];
kornrunner commented 12 months ago

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).

rudiedirkx commented 12 months ago

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.