Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ikhsan017 opened this issue Mar 10, 2014 · 4 comments
Closed

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

ikhsan017 opened this issue Mar 10, 2014 · 4 comments

Comments

@ikhsan017
Copy link

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
Copy link

prisis commented Mar 10, 2014

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

@ikhsan017
Copy link
Author

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
Copy link
Owner

Hey, this is actually an upstream bug in the Twig view, I've sent a pull request with a fix slimphp/Slim-Views#21.

@ikhsan017
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants