CSS Blade Laravel

Asked

Viewed 2,778 times

2

I’m starting now with Laravel 5.1, I was left with a question regarding Lade.

For example, I want to pass several CSS or JS files from the page in question using Blade notation. My main file looks like this:

<html>
<head>
    <link href="@yield('css')" rel="stylesheet">
    <title>@yield('titulo')</title>
</head>

And on the page like this:

@section('css', '/css/app.css')

How can I load multiple CSS files on a given page? It is possible?

1 answer

1

You can create this in a different way by creating a @section only for CSS on its home page. It’s interesting to put views that all pages will use:

// trecho do arquivo layouts/master.blade.php
@section('style')
    <link href="/css/app.css" rel="stylesheet">
@show

And in views based on layouts/master, you will place the page specific views.

@extends('layouts.master')

@section('style')
    @parent
    <link href="/css/app2.css" rel="stylesheet">
    <link href="/css/app3.css" rel="stylesheet">
    <link href="/css/app4.css" rel="stylesheet">        
@endsection

The @parent will pull the contents of the @section and place the specific content below. If you want to overwrite the content of @section just don’t put the @parent

  • I don’t know if we still have that problem at Laravel, but in the Laravel 3 this Rent appeared on the screen, if you didn’t have any "Son"

  • In 5.1 there is no such problem if you do as indicated in the answer.

  • And it’s actually contrary to your statement... Parent might show up if Section doesn’t have a parent

Browser other questions tagged

You are not signed in. Login or sign up in order to post.