A cikin Laravel, shimfidar wuri yana taka muhimmiyar rawa wajen gina mahaɗin mai amfani don aikace-aikacen yanar gizo. Tsari yana wakiltar tsarin gaba ɗaya na shafin yanar gizon, gami da sassa gama gari kamar header
, footer
da sidebar
. A cikin wannan labarin, za mu bincika yadda ake gina shimfidu a ciki Laravel don ƙirƙirar musaya masu sassauƙa da kiyayewa.
Da fari dai, bari mu ƙirƙiri tsari na asali don gidan yanar gizon mu. Fara da ƙirƙirar fayil mai suna app.blade.php
a cikin kundin adireshi. Wannan fayil ɗin zai zama babban shimfiɗar gidan yanar gizon gabaɗaya. resources/views/layouts
Ga misalin abun ciki na app.blade.php
fayil:
<!DOCTYPE html>
<html>
<head>
<title>@yield('title')</title>
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
</head>
<body>
<header>
<h1>Header</h1>
</header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
<main>
@yield('content')
</main>
<footer>
<p>Footer</p>
</footer>
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
A cikin wannan shimfidar wuri, muna amfani da @yield
umarnin don ayyana sassa masu ƙarfi a cikin shimfidar wuri. Misali, @yield('title')
yana bawa yaro damar sokewa da saita taken shafi. Hakazalika, yana bawa yaro damar saka babban abun ciki na shafin. views @yield('content')
views
Da zarar an ƙirƙiri shimfidar wuri, za mu iya ƙirƙirar yaro da ke amfani da wannan shimfidar. Misali, don ƙirƙirar shafi mai irin shimfidar wuri, ƙirƙirar fayil mai suna a cikin kundin adireshi. Wannan fayil ɗin zai tsawaita shimfidar wuri kuma ya ayyana takamaiman abun ciki don shafin: views about
about.blade.php
resources/views
app.blade.php
about
@extends('layouts.app')
@section('title', 'About')
@section('content')
<h2>About Page</h2>
<p>This is the about us page.</p>
@endsection
A cikin misalin da ke sama, muna amfani da @extends
umarnin don gadon app.blade.php
shimfidar wuri. Na gaba, muna amfani da @section
umarnin don ayyana takamaiman abun ciki don title
da content
sassan shafin.
A ƙarshe, muna buƙatar ayyana hanyoyin don haɗa URLs zuwa ɗayan. views
Misali, a cikin routes/web.php
fayil ɗin, zaku iya ƙara hanyoyi masu zuwa:
Route::get('/', function() {
return view('welcome');
});
Route::get('/about', function() {
return view('about');
});
A cikin wannan misalin, an haɗa URL ɗin "/" zuwa welcome.blade.php
view, yayin da /about
URL ɗin ke da alaƙa da about.blade.php
view.
A ƙarshe, gina shimfidu a cikin Laravel yana ba ku damar ƙirƙirar haɗin haɗin yanar gizo don aikace-aikacen gidan yanar gizon ku da sarrafa sassan gama gari kamar header
, footer
da sidebar
. Ta amfani da shimfidu da yaro, za ku iya gina sassauƙa da mu'amala mai iya kiyayewa a cikin. views Laravel