The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Can I have multiples view systems (or templates engines) in the stable release?

Nicolas Granelli's Avatar

Nicolas Granelli

09 Feb, 2012 03:40 PM

I don't need it to be pretty, even a hack would do it. For example having all the views in twig and just one in plain php.

For example, can I configure the app to work with a twig custom view, and then just create a new instance of Slim_View in the the route I need it?

Thanks

  1. 1 Posted by Bill on 02 Mar, 2012 02:47 PM

    Bill's Avatar

    I see no reason why you can't do this explicitly:

    $view = new Slim_View();
    $view->setTemplatesDirectory(
        $app->view->getTemplatesDirectory()
    );
    // append your data...
    $view->display('one_off.php');
    
  2. 2 Posted by Bill on 02 Mar, 2012 02:48 PM

    Bill's Avatar

    Oh, other than maybe loosing any data that's appended to the existing view. Something like the Flash messages.

  3. Support Staff 3 Posted by Andrew Smith on 06 Mar, 2012 04:10 PM

    Andrew Smith's Avatar

    Depending on the version of Slim you are using you can actually do

    $app->view('Twig');
    

    in you closure function, to use Twig in that specific function, while having raw php for all the other functions. This will retain the appended data stored in flash messages.

  4. 4 Posted by Bill on 07 Mar, 2012 12:30 AM

    Bill's Avatar

    Well spotted. Actually looking at the code. This should work if you switch from an initial Twig view back to a basic php Slim_View. What the OP was looking for. See: Slim::view.

  5. Support Staff 5 Posted by Josh Lockhart on 25 Mar, 2012 03:14 PM

    Josh Lockhart's Avatar

    Yes you can swap Views as needed, and data from the previous View should be transferred into the new View.

    You are also welcome to manually instantiate a View instance where necessary and invoke its functions directly without relying on Slim's own render() method.

  6. Josh Lockhart closed this discussion on 25 Mar, 2012 03:14 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac