@@ -319,3 +319,80 @@ $field->setOptions([
319319 // Your options here
320320]);
321321```
322+
323+ Expression
324+ ----------
325+
326+ The ** Expression** column 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+
351+ role :
352+ type : expression
353+ label : app.ui.price
354+ options :
355+ expression : ' "<strong>" ~ value ~ "</strong>"'
356+ htmlspecialchars : false
357+
358+ most_exensive_order_total :
359+ type : expression
360+ label : app.ui.most_exensive_order_total
361+ options :
362+ expression : ' container.get("sylius.repository.order").findMostExpensiveOrder(value).getTotal()'
363+ ` ` `
364+
365+ </details>
366+
367+ <details open><summary>PHP</summary>
368+
369+ ` ` ` php
370+ <?php
371+ // config/packages/sylius_grid.php
372+
373+ use Sylius\Bundle\GridBundle\Builder\Field\ExpressionField;
374+ use Sylius\Bundle\GridBundle\Builder\GridBuilder;
375+ use Sylius\Bundle\GridBundle\Config\GridConfig;
376+
377+ return static function (GridConfig $grid) : void {
378+ $grid->addGrid(GridBuilder::create('app_user', '%app.model.user.class%')
379+ ->addField(
380+ ExpressionField::create('price', 'value ~ "$"')
381+ ->setLabel('app.ui.price')
382+ )
383+ ->addField(
384+ ExpressionField::create('role', '"<strong>" ~ value ~ "</strong>"', htmlspecialchars : false)
385+ ->setLabel('app.ui.role')
386+ )
387+ ->addField(
388+ ExpressionField::create(
389+ ' most_expensive_order_total' ,
390+ ' container.get("sylius.repository.order").findMostExpensiveOrder(value).getTotal()' ,
391+ )
392+ ->setLabel('app.ui.most_exensive_order_total')
393+ )
394+ );
395+ };
396+ ```
397+
398+ </details >
0 commit comments