Sylius Grid Overide , Custom Template


#1

Hi ,

I am trying to override a Grid Controller and display some additional values like total above the grid

But i am Getting below error when using the custom Controller and a twig template file

`> Variable "resources" does not exist.` 

on line
{% set definition = resources.definition %}

My Yml

    inventory:
    resource: |
        alias: app.inventory
        section: admin
        templates: SyliusAdminBundle:Crud
        except: ['show', 'delete','edit']
        redirect: update
        grid: app_inventory
        permission: true
    type: sylius.resource

    app_admin_inventory_index:
path: /inventory
defaults:
    _controller: App\Controller\InventoryController::showAction
    _sylius:
        section: admin
        template: "@SyliusAdmin/Inventory/index.html.twig"
        permission: true  

// Controller code

namespace App\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sylius\Component\Resource\ResourceActions;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use FOS\RestBundle\View\View;




class InventoryController extends ResourceController
{

  /**
 * @param Request $request
 *
 * @return Response
 */
public function showAction(Request $request): Response
{
    $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

    $this->isGrantedOr403($configuration, ResourceActions::SHOW);
    $resource = $this->findOr404($configuration);

    $this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource);

    $view = View::create($resource);

    if ($configuration->isHtmlRequest()) {
        $view
            ->setTemplate($configuration->getTemplate(ResourceActions::SHOW . '.html'))
            ->setTemplateVar($this->metadata->getName())
            ->setData([
                'configuration' => $configuration,
                'metadata' => $this->metadata,
                'resource' => $resource,
                $this->metadata->getName() => $resource,
            ])
        ;
    }

    return $this->viewHandler->handle($configuration, $view);

}
}

#2

Issue fixed, i had to refer the Action as a service in the Service.yml file

_controller: sylius.controller.inventory:showAction