Blade Template - One Tutorial in Laravel 11
<h1>Home: First Page</h1>
{{-- Below is for printing or echo sum of two numbers --}}
{{ 5 + 2 }}
<br><br>
{{-- Print any statement as shown below : --}}
{{ "Hello World" }}
<br><br>
{{-- Print HTML Tags OR JavaScript code as shown below : --}}
{!! "<h1>Hello World</h1>" !!}
<br><br>
{{-- Print JavaScript code as shown below --}}
{{-- {!! "<script>alert('Hello World')</script>" !!} --}}
{{-- Comment Statement --}}
{{-- Assigning value to variable and Print Variable value --}}
@php
$user = "User Variable";
@endphp
{{ $user }}
<br><br>
{{-- Making Array and Printing Array values in List --}}
@php
$names = ["Salman Khan","John Abraham","Shahid Kapoor"];
@endphp
<ul>
@foreach($names as $n)
<li>{{ $n }}</li>
@endforeach
</ul>
<br><br>
{{-- If we want to print variable as it is, we don't want to print variable value --}}
{{-- if we put "@" before curly brackets then instead of printing its value, it will print as it is as shown below : --}}
@php
$userTwo = "Hello";
@endphp
@{{ $userTwo }}
{{-- Here below, "@if()" will print as it is --}}
@@if()
<br><br>
{{-- If we print Array value with Index as shown below : --}}
@php
$fruits = ["Apple","Banana","Orange","Pineapple"];
@endphp
<ul>
@foreach($fruits as $f)
{{-- <li>{{$loop->index}} - {{ $f }}</li> --}}
{{-- <li>{{ $loop->iteration }} - {{ $f }}</li> --}}
{{-- If we want that for first element of loop there will be color is red and
for last element of loop there will be color is green and for remaining elements,
color is black --}}
@if($loop->first)
<li style="color: #ff0000;">{{ $f }}</li>
@elseif($loop->last)
<li style="color: green;">{{ $f }}</li>
@else
<li>{{ $f }}</li>
@endif
@endforeach
<br><br>
{{-- If we want that for even element of loop there will be color is red and
for odd element of loop there will be color is green as shown below : --}}
@foreach($fruits as $f)
@if($loop->even)
<li style="color: #ff0000;">{{ $f }}</li>
@elseif($loop->odd)
<li style="color: green;">{{ $f }}</li>
@endif
@endforeach
</ul>
Above File is resources\views\welcomeTwo File
Below File is routes\web File
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
Comments
Post a Comment