TwigBridge
TwigBridge copied to clipboard
Variables passed by the controller are empty
$ php artisan twig Twig version 1.15.1 Twig Bridge version 0.5.0
HomeController.php:
public function showWelcome()
{
return View::make('hello', array('myvar' => 'test'));
}
hello.twig:
<div class="welcome">
<h1>{% if myvar is empty %} empty {% endif %}</h1>
<h1>{{ myvar }}</h1>
</div>
Output:
<div class="welcome">
<h1> empty </h1>
<h1></h1>
</div>
Is this a bug or am I missing something?
Seems pretty strange. I'll try setting up your use case.
I have the same problem fresh Laravel installation, no other custom packages except the TwigBridge.
The same Twig / Twig bridge version
Tested also: Twig version 1.15.1 Twig Bridge version 0.5.0 Laravel Framework version 4.1.28
HomeController.php
public function showWelcome()
{
return View::make('hello', array('myvar' => 'test-me'));
}
hello.twig
<h1>hello.twig</h1>
<div class="welcome">
<h1>{% if myvar is empty %} empty {% endif %}</h1>
<h1>{{ myvar }}</h1>
</div>
output:
<h1>hello.twig</h1>
<div class="welcome">
<h1></h1>
<h1>test-me</h1>
</div>
I do have a route in route.php, though:
Route::get('/', 'HomeController@showWelcome');
So, this is working for me. Was this helpful?
I can't replicate this.
Could you try checkout with Laravel 4.2 & TwigBridge 0.6.0.
I was having the same problem too. I tried it with laravel 4.2 and TwigBridge 0.6.1, downgraded to 0.6.0 and then reinstalled 0.6.1 and it started working. Maybe this helps someone.
controller:
class TwigExampleController extends BaseController {
public function show() {
$data = ['test' => 'blah'];
return View::make('twigExample', $data);
}
}
view:
{% block content %}
my content {{ test }}
{% endblock %}