FusionCMS is currently in an open beta state and under heavy active development.


Note that Blade is fully documented through Laravel and we would encourage you to check out their official docs, but we will be presenting pieces of documentation here to help newcomers get started quickly.

Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. In fact, all Blade views are compiled into plain PHP code and cached until they are modified. Blade view files use the .blade.php file extension and are stored in the resources/views directory.

Data Display Syntax

You may display data passed to your Blade views by wrapping the variable in curly braces to echo the value. For example, given the following variable:

$name = 'John Doe';

You may display the contents of the name variable like so:

Hello, {{ $name }}.

Note that Blade {{ }} statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks. This means any code markup will not be rendered on the page but displayed as plain text.

You are not limited to displaying the contents of the variables passed to the view. You may also echo the results of any PHP function. In fact, you can put any PHP code you wish inside of a Blade echo statement:

The current UNIX timestamp is {{ time() }}.

Displaying Unescaped Data

By default, Blade {{ }} statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks. If you do not want your data to be escaped and would like to render the code markup it contains, you may use the following syntax:

Hello, {!! $name !!}.

Be very careful when echoing content that is supplied by users of your application. Always use the escaped, double curly brace syntax to prevent XSS attacks when displaying user supplied data.

Display data if exists

Some logic can be expressed through Blade {{ }}:

// Ternary operator
{{ $name ? $name : 'default' }}
// Display variable value if isset
{{ isset($name) ? $name : 'Default' }}
// Isset ternary operator shortcut
{{ $name ?? 'Default' }}

Displaying data for JavaScript

Since many JavaScript frameworks also use "curly" braces to indicate a given expression should be displayed in the browser, you may use the @ symbol to inform the Blade rendering engine an expression should remain untouched. For example:


Hello, @{{ name }}.

In this example, the @ symbol will be removed by Blade; however, {{ name }} expression will remain untouched by the Blade engine, allowing it to instead be rendered by your JavaScript framework.


Blade also allows you to define comments in your views. However, unlike HTML comments, Blade comments are not included in the HTML returned by your application:

{{-- This comment will not be present in the rendered HTML --}}

Directive Syntax

Directives are a special Blade syntax. They're a way to harness the power of PHP functions directly in your views without having to explicitly write out PHP. Directives are marked with an @ before them and may be used as single line functions or have a closure.

Here we'll cover some common directives you'll need to have under your belt for successful theme development. Please visit our Directives reference page for a full list of available directives.


If Statements

You may construct if statements using the @if@elseif@else, and @endif directives. These directives function identically to their PHP counterparts:

@if (count($records) === 1)
    I have one record!
@elseif (count($records) > 1)
    I have multiple records!
    I don't have any records!

For convenience, Blade also provides an @unless directive:

@unless (Auth::check())
    You are not signed in.

In addition to the conditional directives already discussed, the @isset and @empty directives may be used as convenient shortcuts for their respective PHP functions:

    // $records is defined and is not null...

    // $records is "empty"...

Authentication Conditionals

The @auth and @guest directives may be used to quickly determine if the current user is authenticated or is a guest:

    // The user is authenticated...

    // The user is not authenticated...

If needed, you may specify the authentication guard that should be checked when using the @auth and @guest directives:

    // The user is authenticated...

    // The user is not authenticated...

Section Conditional

You may check if a section has content using the @hasSection directive:

    <div class="pull-right">

    <div class="clearfix"></div>

Environment Conditional

You may check if the application is running in the production environment using the @production directive:

    // Production specific content...

Or, you may determine if the application is running in a specific environment using the @env directive:

    // Staging specific content...

Switch Statements

Switch statements can be constructed using the @switch@case@break@default and @endswitch directives:

        First case...

        Second case...

        Default case...


In addition to conditional statements, Blade provides simple directives for working with PHP's loop structures. Again, each of these directives functions identically to their PHP counterparts:

@for ($i = 0; $i < 10; $i++)
    The current value is {{ $i }}

@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>

@forelse ($users as $user)
    <li>{{ $user->name }}</li>
    <p>No users</p>

@while (true)
    <p>I'm looping forever.</p>

When looping, you may use the loop variable to gain valuable information about the loop, such as whether you are in the first or last iteration through the loop.

When using loops you may also end the loop or skip the current iteration:

@foreach ($users as $user)
    @if ($user->type == 1)

    <li>{{ $user->name }}</li>

    @if ($user->number == 5)

You may also include the condition with the directive declaration in one line:

@foreach ($users as $user)
    @continue($user->type == 1)

    <li>{{ $user->name }}</li>

    @break($user->number == 5)

The Loop Variable

When looping, a $loop variable will be available inside of your loop. This variable provides access to some useful bits of information such as the current loop index and whether this is the first or last iteration through the loop:

@foreach ($users as $user)
    @if ($loop->first)
        This is the first iteration.

    @if ($loop->last)
        This is the last iteration.

    <p>This is user {{ $user->id }}</p>

If you are in a nested loop, you may access the parent loop's $loop variable via the parent property:

@foreach ($users as $user)
    @foreach ($user->posts as $post)
        @if ($loop->parent->first)
            This is first iteration of the parent loop.

The $loop variable also contains a variety of other useful properties:

Property Description
$loop->index The index of the current loop iteration (starts at 0).
$loop->iteration The current loop iteration (starts at 1).
$loop->remaining The iterations remaining in the loop.
$loop->count The total number of items in the array being iterated.
$loop->first Whether this is the first iteration through the loop.
$loop->last Whether this is the last iteration through the loop.
$loop->even Whether this is an even iteration through the loop.
$loop->odd Whether this is an odd iteration through the loop.
$loop->depth The nesting level of the current loop.
$loop->parent When in a nested loop, the parent's loop variable.


In some situations, it's useful to embed PHP code into your views. You can use the Blade @php directive to execute a block of plain PHP within your template:


While Blade provides this feature, using it frequently may be a signal that you have too much logic embedded within your template.


Sometimes you may pass an array to your view with the intention of rendering it as JSON in order to initialize a JavaScript variable. For example:

    var app = <?php echo json_encode($array); ?>;

However, instead of manually calling json_encode, you may use the @json Blade directive. The @json directive accepts the same arguments as PHP's json_encode function:

    var app = @json($array);

    var app = @json($array, JSON_PRETTY_PRINT);

You should only use the @json directive to render existing variables as JSON. The Blade templating is based on regular expressions and attempts to pass a complex expression to the directive may cause unexpected failures.


Blade allows you to push to named stacks which can be rendered somewhere else in another view or layout. This can be particularly useful for specifying any JavaScript libraries required by your views.


To render the complete stack contents, pass the name of the stack to the @stack directive.

    <!-- Head Contents -->



To push content to a stack, utilize the @push directive. You may push to a stack as many times as needed.

    <script src="/example.js"></script>


If you would like to prepend content onto the beginning of a stack, you should use the @prepend directive:

    This will be second...

// Later...

    This will be first...
Have questions?

We're always happy to help with code or other questions you might have. Contact support or chat live with us on Discord.

Last edited on Thursday, July 09, 2020 (3 years ago)