Skip to content

How to achieve proper indentation for Twig method chaining? #87

@tsiatka

Description

@tsiatka

When formatting Twig files using Prettier with the prettier-plugin-twig, I'm having trouble achieving the desired indentation for method chaining within a href attribute. Currently, the methods are not placed on new lines in a way that I find readable.

Here is the formatting result I get after using Prettier:

<a class="task-edit"
    href="{{
        ea_url().setDashboard(
            'App\\Controller\\Dashboard\\DashboardController'
        ).setController(
            'App\\Controller\\Dashboard\\CRUD\\TacheCrudController'
        ).setAction(
            'edit'
        ).setEntityId(
            tache.id
        ).set(
            'sort',
            null
        )
    }}">
    <i class="fa-solid fa-edit"></i>
</a>

Expected Behavior :
I would like the formatter to break lines properly, with each method in the chain starting on a new line for better readability, as shown below:

<a class="task-edit"
    href="{{
        ea_url()
            .setDashboard('App\\Controller\\Dashboard\\DashboardController')
            .setController('App\\Controller\\Dashboard\\CRUD\\TacheCrudController')
            .setAction('edit')
            .setEntityId(tache.id)
            .set('sort', null)
    }}">
    <i class="fa-solid fa-edit"></i>
</a>

Here is my current Prettier configuration:

{
  "plugins": ["prettier-plugin-twig"],
  "twigAlwaysBreakObjects": true,
  "twigMultiLineObjects": true,
  "printWidth": 80,
  "tabWidth": 4,
  "useTabs": false
}

Is this the expected behavior or am I misusing the plugin or Prettier's configuration? I suspect I may not fully understand how to configure Prettier or the plugin correctly to achieve my desired result.

I really appreciate the work you've done on this plugin! Thank you for your time! 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions