SyliusCon 2025
Early Bird Deal
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • Sylius Stack Documentation
  • Getting started
  • Cookbook
    • How to customize your admin panel
      • Basic operations
      • Customizing your grids
      • Customizing the logo
      • Customizing the menu
      • Configuring the security access
      • Customizing the page titles
    • How to use in a DDD architecture
      • Architecture overview
      • Resource configuration
      • Basic operations
      • Operation using a grid
  • Admin UI
    • Getting started
  • Bootstrap Admin UI
    • Getting started
  • Resource
    • Resource Bundle documentation
      • Installation
      • Create new resource
      • Configure your resource
      • Configure your operations
      • Validation
      • Redirect
      • Resource factories
      • Providers
      • Processors
      • Responders
      • Legacy Resource Documentation
        • Configuration
        • Services
        • Routing
        • Forms
        • Getting a Single Resource
        • Getting a Collection of Resources
        • Creating Resources
        • Updating Resources
        • Deleting Resources
        • Configuring a state machine
        • Configuration Reference
  • Grid
    • Grid Bundle documentation
      • Installation
      • Creating your first grid
      • Configuring Fields
      • Field types
      • Creating a custom Field Type
      • Creating a custom Action
      • Creating a custom Bulk Action
      • Filters
      • Creating a custom Filter
      • Advanced configuration
      • Configuration Reference
  • 🍀Twig Extra
    • Getting started
  • 🌱Twig Hooks
    • Getting started
    • Passing data to your hookables
    • Making your hookables configurable
    • Autoprefixing feature
    • Composable Layouts with a predictable structure
    • Advanced
      • Ergonomic work with hooks
      • Metadata objects
      • Multiple hooks inside a single template
      • Overriding hookables
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page
  • Default responders
  • Twig Responder
  • Customize Twig template variables
  • API Responder

Was this helpful?

Edit on GitHub
  1. Resource
  2. Resource Bundle documentation

Responders

PreviousProcessorsNextLegacy Resource Documentation

Last updated 1 month ago

Was this helpful?

Responders respond data: transform data to a Symfony response, return a success in a CLI operation.

Default responders

When your operation is an instance of Sylius\Component\Resource\Metadata\HttpOperation two responders are configured by default.

The responder will automatically choose the responder depending on the request format:

Request format
Responder

html

Sylius\Component\Resource\Symfony\Request\State\TwigResponder

json

Sylius\Component\Resource\Symfony\Request\State\ApiResponder

xml

Sylius\Component\Resource\Doctrine\Common\State\ApiResponder

Twig Responder

The Twig responder is used to render data into a Symfony response. It's used for HTML responses.

The variables that are passed to the Twig templates depends on the operation (See chapter).

Customize Twig template variables

Some variables are already available on your operations, but you can add more variables easily.

As an example, we add a foo variable to the Twig template with bar as value.

src/Twig/Context/Factory/ShowSubscriptionContextFactory.php

namespace App\Twig\Context\Factory;

use Sylius\Resource\Context\Context;
use Sylius\Resource\Metadata\Operation;
use Sylius\Resource\Twig\Context\Factory\ContextFactoryInterface;

final class ShowSubscriptionContextFactory implements ContextFactoryInterface
{
    public function __construct(private ContextFactoryInterface $decorated)
    {
    }

    public function create(mixed $data, Operation $operation, Context $context): array
    {
        return array_merge($this->decorated->create($data, $operation, $context), [
            'foo' => 'bar',
        ]);
    }
}

Use it on your operation.

src/Entity/Subscription.php

namespace App\Entity;

use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Show;
use Sylius\Resource\Model\ResourceInterface;

#[AsResource(
    operations: [
        new Show(
            template: 'subscription/show.html.twig',
            twigContextFactory: ShowSubscriptionContextFactory::class,      
        ),
    ],
)
class Subscription implements ResourceInterface
{
}

API Responder

The API responder is used to render serialized data into a Symfony response. It's used for JSON/XML responses.

Configure your operations
Default responders
Twig Responder
Customize Twig template variables
API Responder