Reputation: 4169
I’m using symfony 4 voters and love how it works to grant or deny permission to a controller method.
What I’m trying to achieve now is to check if user has permission to see a specific block in my twig view. I have a voter called Web:
I’d like to do {% if isGranted(‘Web’) %}{% endif %}
Is this possible? otherwise I’d like to get the result of my voter in a variable from the controller that ‘ill pass to the view without necessary denying access to the method/page.
Is this possible?
Thanks.
Upvotes: 0
Views: 755
Reputation: 57
I suggest you export your block into an another template then you include it in your original template with the render function
{{ render(controller('App\\Controller\\MyController::myRenderMethod')) }}
then in MyController you can do :
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class MyController extends AbstractController
{
public function myRenderMethod(Request $request)
{
if ($this->isGranted($attributes, $subject)) {
//call your render method here
}
}
}
Upvotes: 2