smarty-php / smarty

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

Smarty 5: `registerPlugin()` no longer working with names containing non-lowercase characters #907

Closed m-ober closed 1 year ago

m-ober commented 1 year ago

This should output "Test" but gives the following error in Smarty 5 / dev-master. Working with latest 4.x version.

Smarty\CompilerException: Syntax error in template "string:{customTag}" on line 1 "{customTag}" unknown tag 'customtag' in string:{customTag} on line 1

<?php

require 'vendor/autoload.php';

use Smarty\Smarty;
//use \Smarty;

class Functions
{
    public static function customTag()
    {
        return 'Test';
    }
}

$smarty = new Smarty();
$smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'customTag', [Functions::class, 'customTag']);
$smarty->display('string:{customTag}');
wisskid commented 1 year ago

Might be problem with case sensitivity. Does it work when you change the registerPlugin line as follows? $smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'customtag', [Functions::class, 'customTag']);

m-ober commented 1 year ago

Yes, with this change it's working again. But that would require a lot of refactoring in all templates...

wisskid commented 1 year ago

No worries, we'll fix this. Should be easy! Thank you for your bug report.