SlideShare a Scribd company logo
1 of 19
Download to read offline
Laravel Blade Template
IS333 Web based information systems
By. Shaimaa Mohamed Galal
What is template engine?
• Used to code “View” web application pages.
• Template engines are used when you want to
rapidly build web applications that are split into
different components.
• Templates also enable fast rendering of the server-
side data that needs to be passed to the application.
• For example, you might want to have components
such as body, navigation, footer, dashboard, etc.
Blade: Laravel template engine
Code is
rendered
to PHP in
the storage
folder
Original
View
pages
Advantages of Laravel Blade Template
The Blade is a powerful templating engine in a Laravel framework that
provides:
• Clean code (easy to use and readable).
• Separation of business logic and UI.
• Inheritance.
• Easy for Non-PHP front end developers.
• Provide many built in features such as Auto escaping.
• Auto-escaping via avoiding Cross-Site Request Forgery (CSRF)
✓ CSRF is an attack that forces an end user to execute unwanted actions
on a web application in which they’re currently authenticated.
✓ An attacker may trick the users by sending a link via email or chat and
end with executing actions of the attacker’s choosing.
✓ A successful CSRF attack can force the user to perform state changing
requests like transferring funds, changing their email address..etc.
Blade Features
• The blade templating engine provides its own structure such
as conditional statements and loops.
• To create a blade template, create a view file and save it
with a .blade.php extension instead of .php extension.
• The blade templates are stored in the /resources/view.
• The blade templates are rendered to PHP
/storage/framework/view directory.
• The main advantage: creating a master template, which can
be extended by other files.
• You can write plain PHP code in PHP syntax.
• You can write plain PHP code in template syntax.
Declare variable
• Mostly variables are values of input types, however, we can
define a variable for simple testing purposes.
• Syntax
• The above syntax is equivalent to<?php $id=1; ?>.
• Note: the variable declaration will not be used in the
following slides.
@php
$id =1
@endphp
Displaying Data
• If you want to print the value of a variable, then you can do
so by simply enclosing the variable within the curly brackets.
• Syntax
• In blade template, we do not need to write the code
between
• The above syntax is equivalent to<?= $variable ?>.
{{$variable}};
<?php echo $variable; ?>
Displaying Data
• Ternary operator
• In blade template, the syntax of ternary operator can be
written as:
• If the variable is not set for a value, a ‘default value’ string is
printed.
• Note that if the variable is not defined it will show an
‘undefined variable’ error message.
• The above syntax is equivalent to
{{{ $variable or 'default value’}}}
<?= isset($variable) ? $variable : ?default value? ?>
Blade Template Control Statements
1.<html>
2.<body>
3. <font size='5' face='Arial'>
4.@if(($id)==1)
5.student id is equal to 1.
6.@else
7.student id is not equal to 1
8.@endif
9.</font>
10.</body>
11.</html>
Blade Code
Output
Blade Template Control Statements
1.<html>
2. <body>
3. <font size='5' face='Arial'>
4.@unless($id==1)
5.student id is not equal to 1.
6.@endunless
7.</font>
8.</body>
9.</html>
Blade Code
Output
Blade interally changes
unless(condition) into
if(! condition)
For Loop in Blade
• The blade templating engine provides loops such as
• @for, @endfor
• @foreach, @endforeach
• @while, and @endwhile directives. These directives are
used to create the php loop equivalent statements.
@for ($i = 0; $i < 10; $i++)
{{$i}}
@endfor
For each Loop in Blade
• Loop through array and skips displaying an item if not set to
value.
1.@foreach($students as $students)
2.{{{$students}}}
3.@endforeach
Presenter: Subhranil Dalal
Tutorial
• Laravel Blade Template (Arabic Playlist)
https://www.youtube.com/watch?v=UEoR7f1_V
uw

More Related Content

Similar to Lecture15_LaravelGetStarted_SPring2023.pdf

Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
LAB PHP Consolidated.ppt
LAB PHP Consolidated.pptLAB PHP Consolidated.ppt
LAB PHP Consolidated.pptYasirAhmad80
 
Write Generic Code with the Tooling API
Write Generic Code with the Tooling APIWrite Generic Code with the Tooling API
Write Generic Code with the Tooling APIAdam Olshansky
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxAbhijeetKumar456867
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Mohd Harris Ahmad Jaal
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdfHASENSEID
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptxAlkanthiSomesh
 
Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...
Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...
Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...Cetpa Infotech
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfAAFREEN SHAIKH
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGArulkumar
 
javascript 1
javascript 1javascript 1
javascript 1osman do
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDmitry Vinnik
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript ProgrammingRaveendra R
 

Similar to Lecture15_LaravelGetStarted_SPring2023.pdf (20)

Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
LAB PHP Consolidated.ppt
LAB PHP Consolidated.pptLAB PHP Consolidated.ppt
LAB PHP Consolidated.ppt
 
Write Generic Code with the Tooling API
Write Generic Code with the Tooling APIWrite Generic Code with the Tooling API
Write Generic Code with the Tooling API
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptx
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...
Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...
Unleashing the Power of Laravel A Journey to Modern Web Development | CETPA I...
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
 
javascript 1
javascript 1javascript 1
javascript 1
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
 
Laravel level 2 (Let's Practical)
Laravel level 2 (Let's Practical)Laravel level 2 (Let's Practical)
Laravel level 2 (Let's Practical)
 

More from ShaimaaMohamedGalal

Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Data mining ..... Association rule mining
Data mining ..... Association rule miningData mining ..... Association rule mining
Data mining ..... Association rule miningShaimaaMohamedGalal
 
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdf
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdfLecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdf
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdfShaimaaMohamedGalal
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfShaimaaMohamedGalal
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfShaimaaMohamedGalal
 
1. Lecture1_NOSQL_Introduction.pdf
1. Lecture1_NOSQL_Introduction.pdf1. Lecture1_NOSQL_Introduction.pdf
1. Lecture1_NOSQL_Introduction.pdfShaimaaMohamedGalal
 

More from ShaimaaMohamedGalal (10)

Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Data mining ..... Association rule mining
Data mining ..... Association rule miningData mining ..... Association rule mining
Data mining ..... Association rule mining
 
Lecture 0 - Advanced DB.pdf
Lecture 0 - Advanced DB.pdfLecture 0 - Advanced DB.pdf
Lecture 0 - Advanced DB.pdf
 
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdf
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdfLecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdf
Lecture8_AdvancedPHP(Continue)-APICalls_SPring2023.pdf
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdf
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
Lecture9_OOPHP_SPring2023.pptx
Lecture9_OOPHP_SPring2023.pptxLecture9_OOPHP_SPring2023.pptx
Lecture9_OOPHP_SPring2023.pptx
 
2. Lecture2_NOSQL_KeyValue.ppt
2. Lecture2_NOSQL_KeyValue.ppt2. Lecture2_NOSQL_KeyValue.ppt
2. Lecture2_NOSQL_KeyValue.ppt
 
1. Lecture1_NOSQL_Introduction.pdf
1. Lecture1_NOSQL_Introduction.pdf1. Lecture1_NOSQL_Introduction.pdf
1. Lecture1_NOSQL_Introduction.pdf
 
Lecture3.ppt
Lecture3.pptLecture3.ppt
Lecture3.ppt
 

Recently uploaded

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Lecture15_LaravelGetStarted_SPring2023.pdf

  • 1. Laravel Blade Template IS333 Web based information systems By. Shaimaa Mohamed Galal
  • 2. What is template engine? • Used to code “View” web application pages. • Template engines are used when you want to rapidly build web applications that are split into different components. • Templates also enable fast rendering of the server- side data that needs to be passed to the application. • For example, you might want to have components such as body, navigation, footer, dashboard, etc.
  • 3. Blade: Laravel template engine Code is rendered to PHP in the storage folder Original View pages
  • 4. Advantages of Laravel Blade Template The Blade is a powerful templating engine in a Laravel framework that provides: • Clean code (easy to use and readable). • Separation of business logic and UI. • Inheritance. • Easy for Non-PHP front end developers. • Provide many built in features such as Auto escaping. • Auto-escaping via avoiding Cross-Site Request Forgery (CSRF) ✓ CSRF is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. ✓ An attacker may trick the users by sending a link via email or chat and end with executing actions of the attacker’s choosing. ✓ A successful CSRF attack can force the user to perform state changing requests like transferring funds, changing their email address..etc.
  • 5. Blade Features • The blade templating engine provides its own structure such as conditional statements and loops. • To create a blade template, create a view file and save it with a .blade.php extension instead of .php extension. • The blade templates are stored in the /resources/view. • The blade templates are rendered to PHP /storage/framework/view directory. • The main advantage: creating a master template, which can be extended by other files. • You can write plain PHP code in PHP syntax. • You can write plain PHP code in template syntax.
  • 6. Declare variable • Mostly variables are values of input types, however, we can define a variable for simple testing purposes. • Syntax • The above syntax is equivalent to<?php $id=1; ?>. • Note: the variable declaration will not be used in the following slides. @php $id =1 @endphp
  • 7. Displaying Data • If you want to print the value of a variable, then you can do so by simply enclosing the variable within the curly brackets. • Syntax • In blade template, we do not need to write the code between • The above syntax is equivalent to<?= $variable ?>. {{$variable}}; <?php echo $variable; ?>
  • 8. Displaying Data • Ternary operator • In blade template, the syntax of ternary operator can be written as: • If the variable is not set for a value, a ‘default value’ string is printed. • Note that if the variable is not defined it will show an ‘undefined variable’ error message. • The above syntax is equivalent to {{{ $variable or 'default value’}}} <?= isset($variable) ? $variable : ?default value? ?>
  • 9. Blade Template Control Statements 1.<html> 2.<body> 3. <font size='5' face='Arial'> 4.@if(($id)==1) 5.student id is equal to 1. 6.@else 7.student id is not equal to 1 8.@endif 9.</font> 10.</body> 11.</html> Blade Code Output
  • 10. Blade Template Control Statements 1.<html> 2. <body> 3. <font size='5' face='Arial'> 4.@unless($id==1) 5.student id is not equal to 1. 6.@endunless 7.</font> 8.</body> 9.</html> Blade Code Output Blade interally changes unless(condition) into if(! condition)
  • 11.
  • 12. For Loop in Blade • The blade templating engine provides loops such as • @for, @endfor • @foreach, @endforeach • @while, and @endwhile directives. These directives are used to create the php loop equivalent statements. @for ($i = 0; $i < 10; $i++) {{$i}} @endfor
  • 13. For each Loop in Blade • Loop through array and skips displaying an item if not set to value. 1.@foreach($students as $students) 2.{{{$students}}} 3.@endforeach
  • 14.
  • 15.
  • 16.
  • 17.
  • 19. Tutorial • Laravel Blade Template (Arabic Playlist) https://www.youtube.com/watch?v=UEoR7f1_V uw