Open literat opened 2 months ago
I want to have the same functionality as classes/classnames like the npm library for React so I can easily send an array to the class prop.
new TwigFilter('classes', [$this, 'stringifyHtmlClasses']), /** * @param string[] $classes */ public function stringifyHtmlClasses(array $classes): string { return implode(' ', $classes); }
<Text size="large" class="{{ [ 'text-secondary', _person.description ? 'mb-1' : 'mb-0' ]|classes }}" > {{- _person.role -}} </Text>
The join filter wouldn't work for you?
join
[ 'text-secondary', _person.description ? 'mb-1' : 'mb-0' ] | join(' ')
The join filter is basically an implementation of PHP's implode().
implode()
I want to have the same functionality as classes/classnames like the npm library for React so I can easily send an array to the class prop.