@@ -319,3 +319,78 @@ $field->setOptions([
319319 // Your options here
320320]);
321321```
322+
323+ Expression
324+ ----------
325+
326+ The ** Expression** field type provides flexibility by allowing you to specify an expression that will be evaluated on the fly.
327+ This feature uses Symfony's expression language, making it versatile and powerful without needing to create additional callbacks or templates.
328+
329+ The expression will be evaluated with the following context:
330+
331+ - ` value ` : The value of the row.
332+
333+ You can also control whether special characters in the output are escaped by setting the ` htmlspecialchars ` option.
334+ By default, this is enabled, but you can disable it if the output contains HTML elements that should render as HTML.
335+
336+ <details open ><summary >Yaml</summary >
337+
338+ ``` yaml
339+ # config/packages/sylius_grid.yaml
340+
341+ sylius_grid :
342+ grids :
343+ app_user :
344+ fields :
345+ price :
346+ type : expression
347+ label : app.ui.price
348+ options :
349+ expression : ' value ~ "$"'
350+ role :
351+ type : expression
352+ label : app.ui.price
353+ options :
354+ expression : ' "<strong>" ~ value ~ "</strong>"'
355+ htmlspecialchars : false
356+ most_exensive_order_total :
357+ type : expression
358+ label : app.ui.most_exensive_order_total
359+ options :
360+ expression : ' container.get("sylius.repository.order").findMostExpensiveOrder(value).getTotal()'
361+ ` ` `
362+
363+ </details>
364+
365+ <details open><summary>PHP</summary>
366+
367+ ` ` ` php
368+ <?php
369+ // config/packages/sylius_grid.php
370+
371+ use Sylius\Bundle\GridBundle\Builder\Field\ExpressionField;
372+ use Sylius\Bundle\GridBundle\Builder\GridBuilder;
373+ use Sylius\Bundle\GridBundle\Config\GridConfig;
374+
375+ return static function (GridConfig $grid) : void {
376+ $grid->addGrid(GridBuilder::create('app_user', '%app.model.user.class%')
377+ ->addField(
378+ ExpressionField::create('price', 'value ~ "$"')
379+ ->setLabel('app.ui.price')
380+ )
381+ ->addField(
382+ ExpressionField::create('role', '"<strong>" ~ value ~ "</strong>"', htmlspecialchars : false)
383+ ->setLabel('app.ui.role')
384+ )
385+ ->addField(
386+ ExpressionField::create(
387+ ' most_expensive_order_total' ,
388+ ' container.get("sylius.repository.order").findMostExpensiveOrder(value).getTotal()' ,
389+ )
390+ ->setLabel('app.ui.most_exensive_order_total')
391+ )
392+ );
393+ };
394+ ```
395+
396+ </details >
0 commit comments