Active
Project:
Drupal core
Version:
main
Component:
theme system
Priority:
Normal
Category:
Plan
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
22 Jul 2012 at 16:07 UTC
Updated:
20 Nov 2015 at 20:39 UTC
Jump to comment: Most recent
Comments
Comment #1
daggerhart commentedVery late to the game here, sorry if I'm posting this out of place. I'm excited what I am learning about Twig, and want to become involved and help.
Twig filters look incredibly useful, especially since they chain. To answer your questions, I would like to see t() and count() as filters.
Chaining with the replace filter.
{{ node.title|replace({"foo":"bar"})|replace({"bar":"buz"}) }}current t()
twig filter |t()
{{ "2 days in the future is @date"|t({ "@date" : '+2days'|date('M-d-Y') }) }}Seems reasonable to me.
count()
With count, there is already a filter in twig for length. http://twig.sensiolabs.org/doc/filters/length.html
Is there another need count() fulfills that |length doesn't ?
Example iterate using length:
Comment #2
jenlamptonIn Munich, we decided to always use filters over functions, but I'm hesitant to make that decision for one major reason.
Twig functions work just like PHP functions, and Drupal is built on PHP. The learning curve to becoming a Drupal developer starts in the theme layer, and eventually even theme devs will need to know PHP to use preprocess functions. If we start by giving people only filters they'll need to learn yet another syntax.
Right now, the twig engine provides all PHP functions both as functions and as filters. We may decide to change this later on :)
Also - Moving to the active sandbox.
Comment #3
jenlamptonadding tags
Comment #4
jenlamptonComment #5
fabianx commentedThe syntax of:
'Hello'|t(...)
is very nice, but: Can the translation scripts _find_ and detect these.
That might be a reason to stick to t('Hello', ...).
Comment #5.0
fabianx commentedadding issue summary from duplicate issue
Comment #6
joelpittetConsider adding
format_pluralto twig filters, or better yethttp://twig.sensiolabs.org/doc/extensions/i18n.html
With plural and trans blocks
Comment #7
steveoliver commentedMoving this to the core queue with lower priority and marking as task.
Comment #8
steveoliver commentedUpdating title. :/
Comment #9
sutharsan commentedIMO twig documentation is not very clear about what the difference between a function and a filter is. My conclusion is that a Twig filter uses something that can already be outputted and converts it into desired output.
For example:
What is left of the pipe symbol (
name) is meaning full output.While a Twig function uses or acts upon its parameter. The function will return output, but the parameter is (usually) no valid output. This discussion helped me understanding this difference between functions and filters.
From the functions mentioned in the issue summary,
t,showandhidefit in the filter definition:Comment #10
ksenzeeRe #5, the issue for that is #2011442: Support for Drupal 8 twig t filter translatables. It shouldn't be too hard to pick up the new syntax - just a new regex or two. Certainly not a big enough deal that Twig should compromise on the right thing to do here.
Comment #10.0
ksenzeeAdd current state
Comment #11
joelpittetUpdated the current state.
Comment #12
sergeypavlenko commentedHi, all
Now function "hide" not work. There are plans to add it?
I'm use function so:
{% hide(content.links) %}
{% content|hide(content.links) %}
{% content|hide('content.links') %}
Comment #13
star-szrPlease see https://www.drupal.org/node/2212845.
Comment #14
joelpittetRepurposed this issue to track things as a plan.
Comment #15
joelpittetComment #16
joelpittetComment #17
joelpittet