Laravel @stack Directive
The @stack directive allows you to create a field with the specified name. Thus, you can add page-specific content to this field in your other views using the @push directive.
For example, you can show page-specific js, css or some other code only when you enter that page.
In your layout page, in this example mine is layouts/index.blade.php, I created a field called custom-head inside my <head> tag.
// layouts/index.blade.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{ config('app.name', 'Laravel') }}</title>
..
@stack('custom-head')
..
</head>
And now, if I want to add a custom css, js or any code to that page in my subviews, we can use the @push directive.
// users.blade.php
@extends('layout')
@push('custom-head')
<link href="{{ mix('css/users.css') }}">
@endpush
Unlike the @section and @yield directives, you can add content multiple times with these directives. However, the @section and @yield directives add one-time content.
And in addition, remember that you have to specify the page to extend with the @extends directive.
Comments
Popular Articles
Popular Tags
- #directive
- #Function
- #Json
- #Class
- #SASS
- #Form
- #Redirect
- #API
- #Special Characters
- #Special
- #Random
- #Generating
- #
- #Text
- #Ajax
- #URL
- #Encrypting
- #React
- #Show
- #timeAgo
- #PSR-4
- #Hide
- #DDOS Protection
- #DDOS
- #cURL
- #Logic For Displaying Posts
- #Error
- #Key
- #General Error
- #1364 Field
- #Abbreviation
- #Blade
- #Version
- #QR
- #QR Code Generating
- #Array
- #Arrays with Key Values to String Statement
- #Short Tag
- #Activate
- #Real Time
- #Socket.io
- #301
- #Custom Directives
- #Iframe Detection
- #Date
- #Characters
- #Insert
- #Autoloader
- #Composer
- #Reading
There are no comments, make the firs comment