Views
Views & Blade Template Engine
The basic layout of all pages is included in lethal.landings master.blade.php
template, it holds things such as the websites' navigation, footer and more. This can be used by other views to extend it. You can also include plain PHP
code in views. Let's start with a basic example of how you could extend the master template:
<!-- Extend lethal.landings master template -->
@extends('master')
<!-- Add text to the title section, this will basically be added in front of your websites name in the website title. -->
@section('title')
MY CUSTOM PAGE
@endsection
<!-- Add content to the content section in the master template, this is where most of your code should go! -->
@section('content')
<div class="text-center text-light text-uppercase fw-bolder fs-4">
<!-- Return html_entities sanitized php variables by encasing them in {{ $my_variable }} you can also call a function directly. -->
Welcome to my custom Page, {{ currentUser()->name}}!
</div>
<div class="row mt-4">
<div class="col-12">
<div class="panel">
<div class="panel-header">
All the boxes look like this.
</div>
<div class="panel-body">
The UI is built on these basic boxes,
twitter bootstrap v5 is used as css framework!
You can also use FontAwesome by default!
</div>
</div>
</div>
</div>
@endsection
<!-- If your page adds or requires custom JavaScript you can add it here and it will be appended after jQuery has been loaded. -->
@section('additional-js')
<script>
console.log("My fist page with blade...")
</script>
@append
It is that simple! If you just want to show basic html you could also use the build-in Custom Pages
functionality.
Blade Functionality
Below are some more basic explanations if you need more refer to the Laravel Blade Docs or the BladeOne since lethal.landing uses BladeOne.
Plain PHP
- You can still use <?php ?> tags but you can also use @php
& @endphp
.
Echoing Variables
- {{$variable}}
- Shows a variable or evaluates a function. The result is escaped.
- {!!$variable!!}
- Shows a variable or evaluates a function. The result is not escaped.
Logic Functions
- @if($value > 1)
If true this will be retured @else
If not this @endif
-
Switches:
@switch($country) @case(1) if $country == 1 @break @case(2) if $country == 2 @break @defaultcase() if $country anythings else than 1 or 2 @endswitch()
Loop Functions
foreach():
@foreach($users as $user)
This is user {{ $user->id }} will be returned
@endforeach
for():
@for ($i = 0; $i < 2; $i++)
The current value is {{ $i }}<br>
@endfor
// returns
The current value is 0
The current value is 1