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

Support Named Argument when execute function #889

Closed ampmonteiro closed 1 year ago

ampmonteiro commented 1 year ago

In sequence of issue #888 this is not possible with smarty:


{form_open('news/delete',  hidden:['news_id' => {$news['id']}]) nofilter}
        <button>Delete</button>
{form_close() nofilter}

i am using php 8.0 feature called Named Arguments, in this case hidden name parameter and give me this error:

image

Even that @wisskid said in #888 :

Well, Smarty is not PHP. Although the syntax is clearly inspired by PHP, their syntaxes differ greatly. Thus, I would not consider this a bug, but it might be considered as a new feature.

And in smarty requiremts:

Requirements: Smarty can be run with PHP 7.1 to PHP 8.2.

however it is not fully compatible with few new features like Named Arguments which should be mention in the docs.

I still didn't try this with twig but tried with Nette/Latte template which works perfectly fine:


    {form_open(
        'news/delete',
        hidden: ['news_id' => esc($news['id'])]
    )|noescape}

you can see my full code here

wisskid commented 1 year ago

Again, Smarty is not PHP. The fact that Smarty can be run with PHP 7.1 to PHP 8.2 does not mean that the Syntax of Smarty is equal to the syntax of PHP. It is not, in many respects. There are some PHP language constructs that also work in Smarty and vice versa, but the similarities are in fact very limited.

Support for named arguments was suggested in https://github.com/smarty-php/smarty/issues/864 and is still open for consideration.