From: Fabien Potencier Date: Thu, 15 Mar 2012 06:25:00 +0000 (+0100) Subject: merged branch stof/trim_filter (PR #662) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f1186c3832abd4f83b6c58ee671bad368b6a12f4;p=web%2Fkonrad%2Ftwig.git merged branch stof/trim_filter (PR #662) Commits ------- d942d11 Added a trim filter Discussion ---------- Added a trim filter This adds a trim filter in Twig as most people thought it deserves being in the core rather than in the extensions. Closes #634 --------------------------------------------------------------------------- by fabpot at 2012-03-13T16:47:15Z I would have added a second option to control whether you trim on both side, only on the left, or only the right. What do you think? --------------------------------------------------------------------------- by nikic at 2012-03-13T17:15:43Z @fabpot In that case I'd rather add two additional functions `trim_left` (mapping to `ltrim`) and `trim_right` (mapping to `rtrim`). Should be more obvious than some flag at the end :) --------------------------------------------------------------------------- by stof at 2012-03-13T18:47:38Z I tend to think that separate filters would indeed be more obvious. What do you prefer @fabpot ? And for the flag, how would you specify the option to use ? Using a string ? Using boolean flags is not appropriate here (as we have 3 meaningful cases) and I don't really like the string solution. --------------------------------------------------------------------------- by fabpot at 2012-03-13T18:53:08Z I don't like the idea of having 3 different filter just for trimming. That seems overkill to me. --------------------------------------------------------------------------- by stof at 2012-03-13T19:14:12Z which API do you suggest for the filter then ? --------------------------------------------------------------------------- by fabpot at 2012-03-13T19:23:51Z I've no definitive idea. So, perhaps we can just merge what you've done for now. --------------------------------------------------------------------------- by Koc at 2012-03-13T20:17:17Z +1 for merge this. There are different filters for different trimming. I cannot remember but there are some situations when we got string with whitespaces in variable and `{{- my_variable -}}` couldn't help and we cann't use `spaceless` filter because `my_vaiable` contains not html for example. upd: oh, sorry, I haven't noticed comment from @nikic . --------------------------------------------------------------------------- by Tobion at 2012-03-13T21:05:09Z I suggest `function trim($left = true, $right = true)` but `left` and `right` could also be strings. That would cover all cases. --------------------------------------------------------------------------- by raulfraile at 2012-03-13T23:43:28Z I think 3 different filters would be much clearer than using string/boolean parameters. IMO is the same case than strtolower/strtoupper. --- f1186c3832abd4f83b6c58ee671bad368b6a12f4