Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gizmojo's avatar

Syntax error using curly syntax in @class directive

Not sure if I'm doing this wrong or it's a known limitation when ussing curly syntax inside double quotes?

syntax error, unexpected identifier "primary", expecting "]"

@php
    $theme = (object)[
        'colors' => ['primary' => 'red']
    ];
@endphp

Works
<x-test @class(["text- " . $theme->colors['primary']]) />

Doesn't work with curly syntax
<x-test @class(["text-{$theme->colors['primary']}"]) />

Test component simple output the class

<div {{ $attributes }}>test</div>
0 likes
3 replies
Sergiu17's avatar
<x-test class="text-{{ $theme->colors['primary'] }}">
gizmojo's avatar

@Sergiu17 thanks but is there no other way?

I've simiplified my example but would prefer to make use of the @class directive for cleaner conditions.

1 like
tisuchi's avatar

@gizmojo You could also use the class helper function to dynamically generate the class string:

<x-test :class="'text-' . $theme->colors['primary']">

Or this might also work:

<x-test
   :class="['text-' . $theme->colors['primary']]"
>
1 like

Please or to participate in this conversation.