Is it better to use Twig or Token?

Created on 18 August 2024, 5 months ago
Updated 1 September 2024, 4 months ago

Hello,

There is a performance issue, is it better to use Twig or Token?

Twig:
{{ site_setting_field('my_machine_name', 'field_fieldname') }}

Token:
{{ drupal_token('site_settings_entity:my_machine_name:field_fieldname') }}
or
[site_settings_entity:my_machine_name:field_fieldname]

Which performance is faster when extracting or rendering data?

Thank you

💬 Support request
Status

Fixed

Version

2.0

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @msn5158
  • 🇬🇧United Kingdom scott_euser

    I guess you could find a performance analysis tool to view the exact performance but my guess is the twig function will be faster.

    Token is still twig extension, needs to evaluate the token, load the entity, and render.

    Twig extension provided by the module avoids the need to evaluate the token, loads the entity, and render.

  • Status changed to Fixed 5 months ago
  • 🇬🇧United Kingdom scott_euser

    Feel free to re-open if you think there is something the community needs to action, otherwise considering this closed.

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

Production build 0.71.5 2024