PHP Tutorial Laravel 4 Framework (Authentication) - Blade Templating
Laravel 4
- Installing on Ubuntu - local
- Installing on a Shared host
- Installing on Windows
- Creating users table
- Home page with controller and blade
- Blade Templating
- Database connection and sending emails
- Creating user account I - GET
- Creating user account II - POST
- Creating user account III - Error checking & redirecting input
- Creating user account IV - User::create()
- Activating user account I - Mail::send()
- Activating user account II - Update user's status
- User account sign-in I - Route and link
- User account sign-in II - Validation
- User account sign-in III - Login Authentication
- Singing out
- Remember the user
- Changing Password I
- Changing Password II
- Recovering forgotten password I
- Recovering forgotten password II
- User Profile
- Database Migration using artisan
This tutorial is the continuation from Home page with controller and blade.
In this chapter, we'll see how the Laravel template (blade)works, and how other templates share it.
We're going to make a new layout that can be shared with other templates. Then, we extends it and use @yield to get the content from the section of the home blade file. We will also see how to setup the navigation and the link to a page.
We'll make a new file (main.blade.php)in views/layout folder so that other templates can share it.
<!DOCTYPE html> <html> <head> <title>Auth</title> </head> <body> </body> </html>
We'll use this main layout for blade templating in the following sections.
We want to extend the layout we've just made in the previous section. We need to modify home.blade.php like this:
@extends('layout.main') @section('content') Home sweet home!! using @yield & template @stop
The line @extends('layout.main') tells Laravel that we're going to extend the main.blade.php in layout folder. The next line @section('content') indicates that this is the content that goes into the @yield section of the main.blade.php:
<!DOCTYPE html> <html> <head> <title>Auth</title> </head> <body> @yield('content') </body> </html>
By setting this way, we can just switching the @section area for other pages.
So, with the current setup, we get;
If we do page source on it:
We can see the @yield('content') has been replace by the @section('content') content specified in home.blade.php.
Let's create a file navigation.blade.php under views/layout folder:
<nav> <ul> <li> <a href="">Home sweet home!! Naviation</a></li> </ul> </nav>
For the main.blade.php, we just include the file this way;
<!DOCTYPE html> <html> <head> <title>Auth</title> </head> <body> @include('layout.navigation') @yield('content') </body> </html>
In the navigation.blade.php, we can set the link to home like this:
<nav> <ul> <li> <a href="{{ URL::route('home') }}">Home sweet home!! Naviation</a></li> </ul> </nav>
As we can see from the picture, 'home' knows the path and it's because we set that up earlier in routes.php like this:
Route::get('/', array('as' => 'home', 'uses' => 'HomeController@home'));
Laravel 4
- Installing on Ubuntu - local
- Installing on a Shared host
- Installing on Windows
- Creating users table
- Home page with controller and blade
- Blade Templating
- Database connection and sending emails
- Creating user account I - GET
- Creating user account II - POST
- Creating user account III - Error checking & redirecting input
- Creating user account IV - User::create()
- Activating user account I - Mail::send()
- Activating user account II - Update user's status
- User account sign-in I - Route and link
- User account sign-in II - Validation
- User account sign-in III - Login Authentication
- Singing out
- Remember the user
- Changing Password I
- Changing Password II
- Recovering forgotten password I
- Recovering forgotten password II
- User Profile
- Database Migration using artisan
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization