我想覆盖Sylius Grid模板并显示一些计算值
总可用数量 总数量
在显示产品库存的网格上
我已经重写了Controller并渲染了树枝模板。
我的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
//控制器代码
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);
}
}
以下是我得到的错误
Variable "resources" does not exist.
Twig_Error_Runtime
未从树枝模板文件中定义的资源
谢谢