Showing posts with label laravel. Show all posts
Showing posts with label laravel. Show all posts

Tuesday, 22 September 2015

Extending layout in laravel

Extending A Layout

When defining a child page, you may use the Blade @extends directive to specify which layout the child page should "inherit". Views which @extends a Blade layout may inject content into the layout's sections using @section directives. Remember, as seen in the example above, the contents of these sections will be displayed in the layout using @yield:
<!-- Stored in resources/views/child.blade.php -->

@extends('layouts.master')

@section('title', 'Page Title')

@section('sidebar')
    @parent

    <p>This is appended to the master sidebar.</p>
@endsection

@section('content')
    <p>This is my body content.</p>
@endsection
In this example, the sidebar section is utilizing the @parent directive to append (rather than overwriting) content to the layout's sidebar. The @parent directive will be replaced by the content of the layout when the view is rendered.
Of course, just like plain PHP views, Blade views may be returned from routes using the globalview helper function:
Route::get('blade', function () {
    return view('child');
});

Monday, 21 September 2015

Best Php Framework Laravel: How to define the layout of laravel

The two way of defining the blade are template inheritance and section. Both are good to use. I like the section uses. I am just giving some example for that. It is basically good to know the uses for that. Almost all page of web application used the same layout . that is called innner layout and home layout. It is better to define those kind of layout at your web apps. giving you the single blade view.

<!-- Stored in resources/views/layouts/innermaster.blade.php -->

<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>
As you can see on the above example there is HTML mark  up. However, remember the @section and @yield directives, @section is for section of  content and @yield directives is for contents of given section