Easyadminbundle: Get Current CrudId in Twig

Created on 24 Sep 2020  路  3Comments  路  Source: EasyCorp/EasyAdminBundle

I find crudID in twig this method:

{{ ea.crudControllers.findCrudIdByCrudFqcn(ea.crud.controllerFqcn) }}

Is there an easier method?

thanks

All 3 comments

app.request.query.get('crudId')

not very elegant as well, but you can create your custom twig function

public function getCrudId(): string{
    return $this->requestStack->getMasterRequest()->query->get('crudId');
}

and requestStack can be added in twig construct method

private $requestStack;

public function __construct(RequestStack $requestStack){
    $this->requestStack = $requestStack;
}

then in twig
{{ getCrudId() }}
gets you current crud id

thanks jakub, actually, I did open the issue on purpose because someone may search this methods

ha!
you got me thinking, I have few custom actions in my crud controllers and I always had an annoying issue, how to get back to an index page easily, so I created another twig function

    public function getBackUrl( $crudClass ): string {
        return $this->crudUrlGenerator
            ->build()
            ->setController($crudClass)
            ->setAction(Action::INDEX);
    }

then in twig
{{ getBackUrl(ea.crud.controllerFqcn) }}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haithem-rihane picture haithem-rihane  路  4Comments

Ealenn picture Ealenn  路  3Comments

ziobudda picture ziobudda  路  4Comments

ghost picture ghost  路  3Comments

javiereguiluz picture javiereguiluz  路  4Comments