Problem/Motivation

Twig 1.12 introduced named arguments. It's a cool feature that allows you to change the order of filter arguments or to make your code self-documenting.

Unfortunately, the theme() function was created before that, so its first argument is just named "theme". Which is not super clear.

Proposed resolution

Rename the first parameter to be $hook.

API changes

Before this change, the theme function could be called with:

{{ theme(
  theme="item_list__node",
  variables={
    "items": [
      "Test",
      "Test2"
    ],
  }
) }}

And after this change:

{{ theme(
  hook="item_list__node",
  variables={
    "items": [
      "Test",
      "Test2"
    ],
  }
) }}
CommentFileSizeAuthor
#2 3090506-2.patch1.48 KBJohnAlbin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JohnAlbin created an issue. See original summary.

JohnAlbin’s picture

Status: Active » Needs review
FileSize
1.48 KB

Patch!

  • JohnAlbin committed 6fd3392 on 8.x-2.x
    Issue #3090506 by JohnAlbin: Improve named arguments of theme function
    
JohnAlbin’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.