Home /Laravel /Displaying variables in a blade template

Displaying variables in a blade template

In this section, we will define a name variable and pass it to our blade template view

  1. open /app/Http/routes.php
  2. modify the blade route to the following
Route::get(‘blade’, function () {

return view(‘page’,array(‘name’ => ‘The Raven’));

});

We will now update pages.blade.php is display the variable

  1.  Open /resources/views/page.blade.php
  2. Update the contents to the following
@extends(‘layouts.master’)

@section(‘title’, ‘Page Title’)

@section(‘sidebar’)

@parent

This is appended to the master sidebar.

@endsection

@section(‘content’)

<h2>{{$name}}</h2>

This is my body content.

@endsection

• {{$name}} double opening curly braces and double closing curly braces are used to display the value of $name variable.

Leave a Reply