logo
down
shadow

Set Twig layout in controller


Set Twig layout in controller

By : user2953301
Date : November 20 2020, 01:01 AM
around this issue I have multiple subdomains, each with its own layout. Some controllers are shared across subdomains (e.g login), some not. What I'd like to do is to set layout according to domain, so that I would not need to write in each template: , You can set layout variable in your FooController:
code :
class FooController 
{
    function fooAction()
    {
        ...
        return $this->render($template, array(
            'layout' => $layout
        ));
    }
}
{% extends layout %}


Share : facebook icon twitter icon
Embed form controller in twig template: can't redirect in embedded controller after submit

Embed form controller in twig template: can't redirect in embedded controller after submit


By : Bil - ADFG
Date : March 29 2020, 07:55 AM
hope this fix your issue Unfortunately, this is by design. You cannot redirect from embedded controllers. As a workaround, you can post to different URL, save referrer, do stuff you need in there and redirect back with results.
How to call Twig extension filter or function from PHP (controller / service / other twig extension etc )?

How to call Twig extension filter or function from PHP (controller / service / other twig extension etc )?


By : NOFFABEL
Date : March 29 2020, 07:55 AM
this will help Try create service number_format and then invoke it in twig extenstion. In this way you can use it in twig and other services :)
Symfony2, how to render controller's action in a twig template if controller has a constructor

Symfony2, how to render controller's action in a twig template if controller has a constructor


By : axsapronov
Date : March 29 2020, 07:55 AM
hop of those help? For controllers as service you just need to use the service name (@some.controller) and action (yourAction) rather than the controller shortcut (SomeBundle:Some:renderList) as you can see in the Sylius templates.
So it would be...
code :
{{ render(controller('some.controller:yourAction')) }}
$request = $this->container->get('request_stack')->getMasterRequest();
Different Twig-Layout for Authentication in special controller?

Different Twig-Layout for Authentication in special controller?


By : user3682553
Date : March 29 2020, 07:55 AM
I hope this helps you . I would pass along a request parameter from the IFrame, to let the controller know that the request came from the modal, e.g. path/to/your/page?ref=modal-iframe:
Then in the controller I would check if the request parameter is present and correct or the user is logged in. In that case you go on outputing your template, otherwise redirect to the general login route.
code :
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class MyController extends Controller
{
     /*
     * @Template("YourBundle:User:login_registration.html.twig")
     */
     public function myAction(Request $request)
     {
         $securityContext = $this->container->get('security.context');

         if (($request->get('ref') && $request->get('ref') == 'modal-iframe') || 
                    $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
              return array();
         }
         else {
             return new RedirectResponse($this->generateUrl('login'));
         }
     }
}
{% extends (app.user ? "layout1.html" : "layout2.html") %}
Twig rendering Controller in div of another Controller

Twig rendering Controller in div of another Controller


By : TreyPraiy
Date : March 29 2020, 07:55 AM
will be helpful for those in need You mean to generate controller by ajax request? Or you know which controller you need when rendering? If the last one, you can use if:
code :
{% if needCreate %}
{{ render(controller('YourBundle:YourController:CreateLicenseController') }}
{% else %}
{{ render(controller('YourBundle:YourController:ChangeController') }}
{% endif %}
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org