itsgoingd / slim-facades

"Static" interface for various Slim features
74 stars 9 forks source link

View::render and View::display not rendering variable #6

Closed ikhsan017 closed 10 years ago

ikhsan017 commented 10 years ago

Hi,

I am trying to implement twig as slim view renderer,

when I am using Slim-facade to render a view, variable is not passed to the view

template.twig

hello {{ name }}!

the routes.php

View::display('template.twig', array('name' => 'John'));
//this only produce 'Hello !'

$app->render('template.twig', array('name' => 'John'));
//this produce 'Hello John!' perfectly

I am using this code to initiate Slim, slim-facades, and twig

require __DIR__.'/../../vendor/autoload.php';
use SlimFacades\Facade;
use Illuminate\Database\Capsule\Manager as Capsule;

/**
 * Initialize Slim application
 */

$app = new Slim\Slim(array(
    'view'              => new \Slim\Views\Twig(),
    'templates.path'    => __DIR__.'/../views'
));

$view = $app->view();
$view->parserOptions = array(
    'debug' => true,
    'cache' => __DIR__ . '/../storage/cache'
);

$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),
);

// initialize the Slim Facade class

Facade::setFacadeApplication($app);
Facade::registerAliases(array(
    'Model'     => 'Illuminate\Database\Eloquent\Model',
    'Sentry'    => 'Cartalyst\Sentry\Facades\Native\Sentry',
    'App'       => 'SlimFacades\App',
    'Config'    => 'SlimFacades\Config',
    'Input'     => 'SlimFacades\Input',
    'Log'       => 'SlimFacades\Log',
    'Request'   => 'SlimFacades\Request',
    'Response'  => 'SlimFacades\Response',
    'Route'     => 'SlimFacades\Route',
    'View'      => 'SlimFacades\View',
));
prisis commented 10 years ago

did you try View::render('template.twig', array('name' => 'John'));

ikhsan017 commented 10 years ago

since View::render return the rendered view, I use echo here

echo View::render('template.twig', array('name' => 'John'));

but it give the same result, no variable passed

you can clone this repo to reproduce the issue https://github.com/ikhsan017/SlimStarter

_edit_ since $app->render('template.twig', $data) works as expected

I am trying App::render('template.twig', $data) and it also workd

itsgoingd commented 10 years ago

Hey, this is actually an upstream bug in the Twig view, I've sent a pull request with a fix https://github.com/codeguy/Slim-Views/pull/21.

ikhsan017 commented 10 years ago

Hi, I see your pull request was merged to upstream repo, but it is in develop branch.

until it merged to the master branch, I think I can go with App::render() instead of View::display()

edit using "slim-views" : "dev-develop" to for a while till 0.1.2 released