Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Setting global twig form theme from twig templates #56872

Copy link
Copy link
Open
@maciekpaprocki

Description

@maciekpaprocki
Issue body actions

Description

First of all. Terribly sorry if that's already an option and I am just thick :)

I think there's quite a common pattern that causes a bit of issues.

We often have different "dashboards" when developing front ends.

Let's say

admin - for site admins
account - for users

They often don't share much style-wise. For example, when developing with Sylius I generally keep the admin intact, but i do the front end completely custom with different js and CSS.

This currently requires me to add below code to every template in front for every form passed:

{% form_theme form 'front_theme.html.twig' %}

I cannot use it in parent template ( base.html.twig ) as I can have multiple forms, different form names etc. In large systems that's a lot of typing.

Example

Given file structure like:

  • admin/base.html.twig
  • admin/form_theme.html.twig
  • admin/product_edit.html.twig
  • admin/category_edit.html.twig
  • account/base.html.twig
  • account/form_theme.html.twig
  • account/product_edit.html.twig
  • account/category_edit.html.twig

admin and account don't share any CSS and JS. product_edit and category_edit both extend base templates from their folder.

Problem

I need to make a choice so I am setting up admin/form_theme.html.twig as a default global template

Then in account/product_edit.html.twig and account/category_edit.html.twig I need to add form_theme declaration each time for every form I have. This gets pretty tedious with a large amount of dashboards/forms/files.

Solution

Allow overwritting of global form_theme from twig.
The easiest way to do that is probably by reusing the form_theme tag without form variable, but other solutions would be ok too.

Example.

I can still set up global to admin/form_theme.html.twig ( or not ) but then overwrite it in account/base.html.twig by using {% form_theme 'account/form_theme.html.twig' %} ( notice missing second form argument ).

This way I have only one file to change per each dashboard. This would automatically apply to all the forms in this template and all descendant ones. Another usage of this same form_theme in the children templates would behave this same as providing form_theme for single form ( which I would expect is overwritting previous calls or stacking them up ).

Extra points

This could also remove a lot of work when overwritting bundles.

Currently, they require you to either set up a global form_theme or include a form_theme directive in each template. The latter is pain to overwrite as it requires a lot and a lot of changes, so it's generally not the best. With this change setting of global wouldn't be required anymore.

I am happy to implement it if I can figure it out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureFormRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)TwigBridge

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.