Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Form] Exclude templates with form_theme #30289

Open
iluuu1994 opened this Issue Feb 18, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@iluuu1994
Copy link
Contributor

iluuu1994 commented Feb 18, 2019

I have multiple form themes configured in my twig.yaml:

twig:
    form_themes:
        - 'bootstrap_4_layout.html.twig'
        - 'form/form_row.html.twig'
        - 'form/form_checkbox_radio.html.twig'
        - 'form/errors.html.twig'

I need to exclude one of these templates (form/form_checkbox_radio.html.twig) for a single form field. Because form_theme adds templates by default, I need to use the only flag:

{% form_theme form.someField with [
    'bootstrap_4_layout.html.twig',
    'form/form_row.html.twig',
    'form/errors.html.twig',
] only %}
{{ form_row(form.someField) }}

One small annoyance is that, since I must use the only flag to remove a template, I need to repeat all the templates that I have specified in my twig.yaml file. If I were to add one more template I'll need to go to all the places where this happened and add the new template. This is error prone.

What would be nice is something like this:

{% form_theme form.someField with not ['template_i_want_to_remove.html.twig'] %}
{{ form_row(form.someField) }}

If at the same time you need to add another template, you could do this:

{% form_theme form.someField with ['template_i_want_to_add.html.twig'] not ['template_i_want_to_remove.html.twig'] %}
{{ form_row(form.someField) }}

The syntax is debatable.

@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

iluuu1994 commented Feb 18, 2019

Are there any objections/suggestions? If not I'll implement this as described and send a PR.

@dsentker

This comment has been minimized.

Copy link

dsentker commented Feb 25, 2019

I suggest "without" instead of "with not". It's easier to read and easier to understand.

@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

iluuu1994 commented Feb 25, 2019

I chose with not for two reasons:

  1. Both are already keywords and used extensively in Twig
  2. By having two keywords you add and remove templates simultaneously {% form_theme ... with [...] not [...] %}
@iluuu1994

This comment has been minimized.

Copy link
Contributor Author

iluuu1994 commented Feb 25, 2019

I created a POC a few days ago. Not sure if this will be possible without a BC break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.