{"id":165,"date":"2026-05-20T15:53:55","date_gmt":"2026-05-20T15:53:55","guid":{"rendered":"https:\/\/gigz.pk\/php\/?post_type=lesson&#038;p=165"},"modified":"2026-05-21T14:42:54","modified_gmt":"2026-05-21T14:42:54","slug":"blade-templates","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/php\/?lesson=blade-templates","title":{"rendered":"Blade Templates"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction to Blade Templates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Blade is the powerful templating engine provided by the PHP framework Laravel. It helps developers create dynamic and reusable website layouts using clean and simple syntax.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Blade templates allow developers to separate the presentation layer from application logic, making web applications easier to manage, maintain, and scale.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Blade files use the <code>.blade.php<\/code> extension and are stored inside the <code>resources\/views<\/code> directory in Laravel projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Objectives<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By the end of this training, you will be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand the purpose of Blade Templates<\/li>\n\n\n\n<li>Create Blade view files<\/li>\n\n\n\n<li>Use Blade syntax for displaying data<\/li>\n\n\n\n<li>Work with layouts and reusable components<\/li>\n\n\n\n<li>Apply conditional statements and loops<\/li>\n\n\n\n<li>Pass data from controllers to views<\/li>\n\n\n\n<li>Build dynamic and organized website interfaces<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Blade Templates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Blade templates are lightweight view files used to create the frontend interface of Laravel applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Blade provides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Simple syntax<\/li>\n\n\n\n<li>Faster development<\/li>\n\n\n\n<li>Reusable layouts<\/li>\n\n\n\n<li>Dynamic content rendering<\/li>\n\n\n\n<li>Clean code structure<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a Blade File<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Example of a Blade template file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>resources\/views\/home.blade.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Basic Blade template example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Home Page&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<br><br>&lt;h1&gt;Welcome to Blade Templates&lt;\/h1&gt;<br><br>&lt;\/body&gt;<br>&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Displaying Data in Blade<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Blade uses double curly braces to display variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h1&gt;{{ $name }}&lt;\/h1&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Controller example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function index()<br>{<br>    $name = \"Ali\";<br>    return view('home', compact('name'));<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Blade Comments<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Blade comments are not visible in the browser source code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{{-- This is a Blade comment --}}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conditional Statements in Blade<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">If Statement<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@if($marks &gt;= 50)<br>    &lt;p&gt;Pass&lt;\/p&gt;<br>@endif<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">If Else Statement<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@if($age &gt;= 18)<br>    &lt;p&gt;Eligible&lt;\/p&gt;<br>@else<br>    &lt;p&gt;Not Eligible&lt;\/p&gt;<br>@endif<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Loops in Blade<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Foreach Loop<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@foreach($students as $student)<br>    &lt;p&gt;{{ $student }}&lt;\/p&gt;<br>@endforeach<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">For Loop<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@for($i = 1; $i &lt;= 5; $i++)<br>    &lt;p&gt;{{ $i }}&lt;\/p&gt;<br>@endfor<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Blade Layouts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Blade layouts help developers create reusable website structures.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Master Layout Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;@yield('title')&lt;\/title&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;<br><br>&lt;header&gt;<br>    &lt;h1&gt;Website Header&lt;\/h1&gt;<br>&lt;\/header&gt;<br><br>&lt;div&gt;<br>    @yield('content')<br>&lt;\/div&gt;<br><br>&lt;footer&gt;<br>    &lt;p&gt;Website Footer&lt;\/p&gt;<br>&lt;\/footer&gt;<br><br>&lt;\/body&gt;<br>&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Extending Layouts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Child views can extend master layouts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@extends('layout')<br><br>@section('title', 'Home Page')<br><br>@section('content')<br>    &lt;h2&gt;Welcome to Home Page&lt;\/h2&gt;<br>@endsection<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Including Blade Files<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Blade allows reusable partial files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@include('navbar')<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Blade Components<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Components help create reusable UI sections.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;x-alert \/&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Passing Data to Blade Views<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Example from controller:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function dashboard()<br>{<br>    $users = &#91;'Ali', 'Ahmed', 'Sara'];<br><br>    return view('dashboard', compact('users'));<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Blade view:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@foreach($users as $user)<br>    &lt;p&gt;{{ $user }}&lt;\/p&gt;<br>@endforeach<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Blade Directives<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Common Blade directives include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>@if<\/code><\/li>\n\n\n\n<li><code>@else<\/code><\/li>\n\n\n\n<li><code>@foreach<\/code><\/li>\n\n\n\n<li><code>@for<\/code><\/li>\n\n\n\n<li><code>@include<\/code><\/li>\n\n\n\n<li><code>@extends<\/code><\/li>\n\n\n\n<li><code>@section<\/code><\/li>\n\n\n\n<li><code>@yield<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These directives simplify frontend development in Laravel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages of Blade Templates<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Easy to learn and use<\/li>\n\n\n\n<li>Clean and readable syntax<\/li>\n\n\n\n<li>Faster website development<\/li>\n\n\n\n<li>Reusable layouts and components<\/li>\n\n\n\n<li>Secure data rendering<\/li>\n\n\n\n<li>Excellent integration with Laravel<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Real World Uses of Blade Templates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Blade Templates are used for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Dynamic websites<\/li>\n\n\n\n<li>Admin dashboards<\/li>\n\n\n\n<li>E-commerce platforms<\/li>\n\n\n\n<li>Content management systems<\/li>\n\n\n\n<li>Student portals<\/li>\n\n\n\n<li>Business web applications<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep templates clean and organized<\/li>\n\n\n\n<li>Use layouts for consistency<\/li>\n\n\n\n<li>Create reusable components<\/li>\n\n\n\n<li>Avoid excessive logic inside views<\/li>\n\n\n\n<li>Use meaningful file names<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Final Presentation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In your final presentation, explain:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What Blade Templates are<\/li>\n\n\n\n<li>Why Blade is important in Laravel<\/li>\n\n\n\n<li>Blade syntax basics<\/li>\n\n\n\n<li>Layouts and reusable views<\/li>\n\n\n\n<li>Loops and conditional statements<\/li>\n\n\n\n<li>Real-world usage of Blade Templates<\/li>\n<\/ul>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/php\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Professional PHP > Laravel Framework Basics > Blade Templates<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779292443698\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":57,"template":"","class_list":["post-165","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Blade Templates - Learn PHP with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn Blade Templates in Laravel with layouts, directives, loops, components, and dynamic website examples\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/php\/?lesson=blade-templates\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Blade Templates - Learn PHP with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn Blade Templates in Laravel with layouts, directives, loops, components, and dynamic website examples\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/php\/?lesson=blade-templates\" \/>\n<meta property=\"og:site_name\" content=\"Learn PHP with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-21T14:42:54+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=blade-templates\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=blade-templates\",\"name\":\"Blade Templates - Learn PHP with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\"},\"datePublished\":\"2026-05-20T15:53:55+00:00\",\"dateModified\":\"2026-05-21T14:42:54+00:00\",\"description\":\"Learn Blade Templates in Laravel with layouts, directives, loops, components, and dynamic website examples\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=blade-templates#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=blade-templates\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=blade-templates#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/php\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Professional PHP > Laravel Framework Basics > Blade Templates\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/\",\"name\":\"Learn PHP with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Blade Templates - Learn PHP with GiGz.PK","description":"Learn Blade Templates in Laravel with layouts, directives, loops, components, and dynamic website examples","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/php\/?lesson=blade-templates","og_locale":"en_US","og_type":"article","og_title":"Blade Templates - Learn PHP with GiGz.PK","og_description":"Learn Blade Templates in Laravel with layouts, directives, loops, components, and dynamic website examples","og_url":"https:\/\/gigz.pk\/php\/?lesson=blade-templates","og_site_name":"Learn PHP with GiGz.PK","article_modified_time":"2026-05-21T14:42:54+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/php\/?lesson=blade-templates","url":"https:\/\/gigz.pk\/php\/?lesson=blade-templates","name":"Blade Templates - Learn PHP with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/php\/#website"},"datePublished":"2026-05-20T15:53:55+00:00","dateModified":"2026-05-21T14:42:54+00:00","description":"Learn Blade Templates in Laravel with layouts, directives, loops, components, and dynamic website examples","breadcrumb":{"@id":"https:\/\/gigz.pk\/php\/?lesson=blade-templates#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/php\/?lesson=blade-templates"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/php\/?lesson=blade-templates#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/php"},{"@type":"ListItem","position":2,"name":"Professional PHP > Laravel Framework Basics > Blade Templates"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/php\/#website","url":"https:\/\/gigz.pk\/php\/","name":"Learn PHP with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}