TwigBridge icon indicating copy to clipboard operation
TwigBridge copied to clipboard

Variables passed by the controller are empty

Open ibrambe opened this issue 10 years ago • 5 comments

$ 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?

ibrambe avatar Mar 26 '14 20:03 ibrambe

Seems pretty strange. I'll try setting up your use case.

rcrowe avatar Mar 29 '14 20:03 rcrowe

I have the same problem fresh Laravel installation, no other custom packages except the TwigBridge.
The same Twig / Twig bridge version

pawel-dubiel avatar May 01 '14 12:05 pawel-dubiel

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?

ghost avatar May 01 '14 20:05 ghost

I can't replicate this.

Could you try checkout with Laravel 4.2 & TwigBridge 0.6.0.

rcrowe avatar May 16 '14 21:05 rcrowe

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 %}

markslemko avatar Aug 28 '14 04:08 markslemko