php

Generating a Link to a CSS File

Problem

You want to add a link to a CSS file in your Blade template.

Solution

Use the HTML::style() method.

You can just pass the path to the style sheet.

{{ HTML::style('css/style.css') }}

This will add the following HTML.

<link media="all" type="text/css" rel="stylesheet"
  href="http://your.url/css/style.css">

If the file path you pass isn’t a complete URL, Laravel will use your application’s URL to build a complete URL.

You can pass additional attributes in an array as the second argument. This also allows you to override the default attributes

{{ HTML::style('css/style.css', array('media' => 'print')) }}

Now the media is “print” instead of the default “all”.

<link media="print" type="text/css" rel="stylesheet"
  href="http://your.url/css/style.css">

About the author

laravelrecipies