T
T
Tarrissarh2015-12-03 22:58:33
Twig
Tarrissarh, 2015-12-03 22:58:33

How to properly use twig in laravel?

Here I installed laravel, installed twig, jquery, bootstrap, etc. dependencies to it
in resource\views\ made base.twig & home.twig
routes.php:
Route::get('/', '[email protected]');
HomeController:

<?php namespace App\Http\Controllers;

class HomeController extends Controller {
  public function __construct()
  {
    $this->middleware('auth');
  }
  public function index()
  {
    return view('home');
  }
}

I go to the site, it redirects to the authorization page.
Where do I need to connect to make twig work?
At the same time, where and how to connect jquery and bootstrap?
I've already looked at a lot of things, but I still haven't found how to do it...
PS I want to use twig instead of blade.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Finnish, 2015-12-04
@Tarrissarh

I advise you to use this tool: https://github.com/rcrowe/TwigBridge
It integrates perfectly with Laravel, even "compositors" work perfectly.
As for jquery and bootstrap, you need to improve your knowledge of HTML, in particular information about head, script and link tags.

J
javanub, 2015-12-03
@javanub

$this->middleware('auth');
Well, you yourself put $this->middleware('auth') in the constructor, which actually redirects you to the authorization page. Maybe first the basics, and then the packages?

N
newpy, 2015-12-04
@newpy

Why did you decide that simply renaming the blade.php files to twig will make twig work for you?
Laravel has its own template engine. In order to use the twig, you need to connect it. You need to include Twig in the core of the application. Not just rename files or install it.
Another question is why do you need this if there is already a built-in template engine? You need to really understand the differences or the need to come to the replacement of one template engine with another.
And where does the tweak and redirect to authorization? Twig has no effect on this. You have already been answered that the redirect to authorization works because of the line added to the controller constructor $this->middleware('auth'). By doing this, you call the authorization middleware, which means that until you log in, the controller will not work for you.
Do you understand the meaning of what you write? Or is it worth getting the basics right? about authorization. I will give you advice to use Blade for now and return everything as it was.
If you figured it out, then it would be worth posting the code how you connected Twig.
With authorization: just remove the constructor in the controller, and the application will not require authorization. If you conceived in such a way that it is still needed, then leave it and authorize the user when executing any controller method.
Essentially two answers have already been given to you: Finnish about using TwigBridge, and javanub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question