[1.0.0-beta2] Short form of icon() twig function

Created on 27 August 2024, 4 months ago
Updated 9 September 2024, 3 months ago

Problem/Motivation

Today, icon Twig function expects 3 parameters: {{ icon("my_pack", "this_icon", {foo: "bar"}) }}

The last one is optional: IconTwigExtension::getIconRenderable(string $icon_pack_id, string $icon_id, ?array $settings = []): array

However, when used with injected icon structure, like the UI Patterns 1.x setting type or the UI Patterns 2.x prop type, it is error prone to write: {{ icon(icon1.icon_pack, icon1.icon, icon1.settings) }}

We already have an icon structure:

{% set icon = {
 icon_pack: "my_pack",
 icon: "this_icon",
 settings: {foo: "bar"}
} %} 

So, why not also allowing this: {{ icon(icon) }} ?

Proposed resolution

This proposal was made during a weekly meeting, we are not sure it is relevant. Let's talk about this before any commit.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

  • Issue created by @pdureau
  • 🇫🇷France celdia

    It always makes writing easier.

    I guess {{ icon("my_pack", "this_icon", {foo: "bar"}) }} is the icon definition, right ?

    So wouldn't be better to write {{ icon(iconDefinition) }} for example ?

  • 🇫🇷France mogtofu33

    Hi @pdureau, the request is to replace or keep both available?

  • 🇫🇷France pdureau Paris

    Hi @pdureau, the request is to replace or keep both available?

    The existing form (3 parameters) is the expected one. It needs to be kept. The proposal is an alternative form.

    Personally, I am not 100% convinced about introducing this new form.

    So wouldn't be better to write {{ icon(iconDefinition) }} for example ?

    Indeed, but iconDefinition must be a Twig mapping, not an executable PHP objetc

  • 🇫🇷France pdureau Paris

    After a few weeks of real life use and feedbacks, we consider the current icon() function as OK enough

Production build 0.71.5 2024