From: Fabien Potencier Date: Fri, 16 Nov 2012 07:04:33 +0000 (+0100) Subject: merged branch fabpot/named-arguments (PR #901) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=158ed4e88cc336724c9605f5f15a6ef859466703;p=web%2Fkonrad%2Ftwig.git merged branch fabpot/named-arguments (PR #901) This PR was merged into the master branch. Commits ------- 4647913 added the ability to set default values for macro arguments (closes #447) a59dcde added support for named arguments for filters, tests, and functions 65637b7 refactored the code handling arguments for PHP callbacks when compiling nodes Discussion ---------- Named arguments and macro default values This PR contains two new features. Even if they are not related, the code needed to make them work was almost the same. The first feature is the ability to use named arguments for functions, tests, and filters: ```jinja {{ data|convert_encoding('UTF-8', 'iso-2022-jp') }} {# versus #} {{ data|convert_encoding(from='iso-2022-jp', to='UTF-8') }} ``` The syntax is borrowed from Python where named arguments are part of the language. The second feature is the ability to defined default values for macro arguments: ```jinja {% macro input(name, value = "", type = "text", size = 20) %} {% endmacro %} ``` More information in the updated documentation. These features have been implemented with BC in mind (which means that the code is not optimal, but it will be completely refactored for Twig 2.0 where we will get rid of all those ridiculous `Twig_Filter_*` and `Twig_Function_*` classes). --------------------------------------------------------------------------- by fabpot at 2012-11-15T10:34:16Z I forgot to mention that there is no overhead if you are not using these new features, and that the overhead is only at compilation time (the compiled templates are the same as before). --------------------------------------------------------------------------- by marekkalnik at 2012-11-15T10:36:49Z That are some great features, thanks ! :+1: --------------------------------------------------------------------------- by lolautruche at 2012-11-15T10:46:42Z Nice ! :+1: @fabpot So I guess the old behavior is kept, isn't it ? --------------------------------------------------------------------------- by fspillner at 2012-11-15T10:50:31Z Awesome! --------------------------------------------------------------------------- by fabpot at 2012-11-15T11:28:20Z @lolautruche yes, the old way still works of course. --------------------------------------------------------------------------- by Seldaek at 2012-11-15T11:42:40Z Awesome! This has been much needed a few times in the past. We can almost drop php altogether and just write twig :P --------------------------------------------------------------------------- by marfillaster at 2012-11-15T12:07:43Z @Seldaek maybe a twig to php processor --------------------------------------------------------------------------- by Seldaek at 2012-11-15T12:14:34Z @marfillaster that's already what twig is :) --------------------------------------------------------------------------- by Tobion at 2012-11-15T12:38:28Z @fabpot nice stuff --------------------------------------------------------------------------- by simensen at 2012-11-15T16:01:03Z This looks great! --------------------------------------------------------------------------- by sstok at 2012-11-15T19:18:53Z This was basically the only thing missing I was missing in Twig :100: :+1: --------------------------------------------------------------------------- by jorgelbg at 2012-11-15T20:05:15Z I love this new feauture, it's great to have this on Twig! Brings a lot of clarity to my future templates ;-) --- 158ed4e88cc336724c9605f5f15a6ef859466703