Skip to content

Nullsafe attribute in twig component #3704

Description

@ThibaultJlvt

Hi,

I've just migrated from v2.32.0 to v2.36.0.
Since then, I have some issues with my twig component and more precisely the nullsafe operator :

Before migration :

<twig:Page
    title="Commandes - Affaire : {{ affaire.numero }}"
    breadcrumb="Accueil > <a href='{{ pathIndex }}'>Affaires</a> > {{ lienParent }} {{ lienAffaire }} > Commandes"
    pageTitle="Affaire : {{ affaire.numero ~ ' - ' ~ affaire.commune?.organisation?.raisonSociale ~ ' - ' ~ affaire.libelle }}"
    :menuTabs="menu_tabs"
    :menu="menu"
>

In Page.html.twig :

<h2 class="page-title">
   {{ this.pageTitle }}
</h2>

Was working fine.

But now, if organisation is null, I get : "Impossible to access an attribute ("raisonSociale") on a null variable".

I have to set the variable before :
{% set pageTitle = "Affaire : " ~ affaire.numero ~ ' - ' ~ affaire.commune?.organisation?.raisonSociale ~ ' - ' ~ affaire.libelle %} And then :
:pageTitle="pageTitle"

I've migrated to v3.2.0 to see if there was a little regression that was corrected but no.

Am I missing something ?

Thank you !

Ps : I'm using twig/twig version v3.28.0
and <twig:Page :pageTitle="affaire.commune?.organisation?.raisonSociale" /> not working neither

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions