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

Modifier syntax changed? Spaces around `|` causes error #887

Closed wxiaoguang closed 1 year ago

wxiaoguang commented 1 year ago

Before it works:

{$var | string_format:"%.2f"}

But with 4.3.1, it reports error:

Syntax error in template "my.tpl" on line 33 "<td>{$var | string_format:"%.2f"} MB</td>" - Unexpected "|"

Removing the spaces then {$var|string_format:"%.2f"} works in 4.3.1.

It looks like a regression?

wisskid commented 1 year ago

Do you know what the latest version is where your syntax still works? Thanks.

wisskid commented 1 year ago

It's not a regression, at least not a recent one. I tested it against 3.1.46 with the same result. You're probably coming from Smarty v2? The v2 > v3 upgrade guide doesn't specifically mention your codestyle, but it does mention that Smarty 3 has a new syntax, which is stricter. It also mentions whitespace from being important now. Since v3 has been out over a decade now, we will stick to the v3 syntax.

wxiaoguang commented 1 year ago

Thank you for your help. I think you are right. The project is very old and was using Smarty v2 long time ago. It has been running with Smarty v3/v4 for long time. Maybe the template with the old syntax is seldom used, so I didn't notice the error until today.

I will do more checks, thank you again.