Skip to content
Aaron Lord edited this page May 12, 2013 · 4 revisions

Defining a layout

Filename: app/views/layouts/master.php

    <!doctype html>
    <html>
    <body>
        <header>
            <nav>
                <ul>
                    @section('nav')
                        <li><a href="#">Home</a></li>
                        <li><a href="#">About</a></li>
                        <li><a href="#">Contact Us</a></li>
                    @show
                </ul>
            </nav>
        </header>

        <div class="container" role="main">
            @yield('content')
        </div>
    </body>
    </html>

Using a layout

Filename: app/views/hello.php

    @layout('layouts.master')

    @section('content')
        <p>This is my websites main content.</p>
    @stop

    @section('nav')
        @parent
        <li><a href="#">Blog</a></li>
    @stop

Echoing data

    Greetings {{ $name }},
    how're you on this glorious {{ data('l', time()) }}.

    Here is some {{{ $escaped }}} data.

Conditional statements

    @if ($foo == 'foo')
        Great example.
    @elseif ($bar == 'bar)
        Seriously.
    @else
        I don't even.
    @endif

Loops

    @for ($i = 0; $i < 10; $i++)
        Counting: {{ $i }}
    @endfor

    @while (true)
        Forever.
    @endwhile

    @foreach ($people as $person)
        Hey {{ $person }}, how're you?
    @endforeach

    @forelse ($people as $person)
        Hey {{ $person }}, how're you?
    @empty
        No people :(
    @endforelse

Clone this wiki locally