2

I want to have project with:

  • Laravel 5
  • Twig template engine
  • trans tag in Twig, which works with standard Laravel translations (based on php arrays)

Here is my composer.json:

"require": {
    "laravel/framework": "5.1.*",
    "rcrowe/TwigBridge": "~0.8.1"
}

app.php:

'providers' => [
    // ...
    TwigBridge\ServiceProvider::class,
    // ...
]

'aliases' => [
    'Twig'      => TwigBridge\Facade\Twig::class,
],

Here is my controller:

class Page extends Controller
{
    public function home()
    {
        $name = 'Guest';
        return Twig::render('twig.twig', compact('name'));
    }
}

But I have this error:

ReflectionException in Container.php line 736:
Class view does not exist
Aleksey Razbakov
  • 624
  • 8
  • 29

2 Answers2

0

I've used the TwigBridge multiple times in my projects without getting that error, but instead of Twig::render you can still use the standard Laravel View::make functionality. https://github.com/rcrowe/TwigBridge#usage

My steps for installation:

  1. Require in composer
  2. Add the service provider 'TwigBridge\ServiceProvider',
  3. Add the facase 'Twig' => 'TwigBridge\Facade\Twig',
  4. Use the View::make or view('view', $params)

The default translator class of Laravel is already included in the TwigBridge so you can just use {{ trans('website.key') }} if i remember correctly https://github.com/rcrowe/TwigBridge#functionsfiltersvariables

Sven Buijsrogge
  • 139
  • 1
  • 13
  • I tried also your way to write app.php, but it throws the same error. Can you check if it works for you? Maybe smth is broken in Laravel or TwigBridge? Now I have error: ReflectionException in Container.php line 736: Class view does not exist – Aleksey Razbakov Aug 24 '15 at 14:47
  • @razbakov What did you try to write in your app.php? – Sven Buijsrogge Aug 27 '15 at 12:16
0

I had the same problem as yours, try to add provider and aliases in the end of variables (after View)

Fajar Ulin Nuha
  • 399
  • 2
  • 7