Skip to content

Conversation

@jcrombez
Copy link

Simple way to add a translate twig filter when using a placeholder on a select2.

Simple way to add a translate twig filter when using a placeholder on a select2.
@jcrombez
Copy link
Author

Any opinion from the maintainer(s) ?

$field = $('#{{ id }}');
{% if configs.placeholder is defined %}
{% set configs = {'placeholder': configs.placeholder|trans} + configs %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{% set configs.placeholder = configs.placeholder|trans %}

would be better optmized.
Also a possibility to fetch the translation domain from the form config itself

Copy link

@benschumi benschumi Dec 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neirda24, your code doesn't work.

Unexpected token "punctuation" of value "." ("end of statement block" expected) in GenemuFormBundle:Form:jquery_layout.html.twig at line 661.

The original method by jcrombez work well
{% set configs = {'placeholder': configs.placeholder|trans} + configs %}
but i prefer this
{% set configs = configs|merge({"placeholder": configs.placeholder|trans}) %}

$field = $('#{{ id }}');
{% if configs.placeholder is defined %}
{% set configs = {'placeholder': configs.placeholder|trans} + configs %}
Copy link

@benschumi benschumi Dec 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neirda24, your code doesn't work.

Unexpected token "punctuation" of value "." ("end of statement block" expected) in GenemuFormBundle:Form:jquery_layout.html.twig at line 661.

The original method by jcrombez work well
{% set configs = {'placeholder': configs.placeholder|trans} + configs %}
but i prefer this
{% set configs = configs|merge({"placeholder": configs.placeholder|trans}) %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants