Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed css to HTML in laravel?

First of all, to make things clear, I know I can include my css file by

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

Which the html to be generated will be:

<link rel="stylesheet" type="text/css" href="http://myhost/public/css/myStyle.css">

The problem is that my view file is used for email and many email client don't load external css file. So I need to make it something like:

<style>
    .content-of-my-css {
        //content of my css
    }
    // more css
</style>

As the css settings will be used for multiple email template, I don't want to hard code it. In pure PHP, this can be done by (reference)

<style><?php include "path/to/my/css";?></style>

However, when I do that with laravel, it says:

ErrorException (E_ERROR) include(): http:// wrapper is disabled in the server configuration by allow_url_include=0

So, is there a way I can embed the css in laravel? (I am using laravel 4.2)

like image 379
cytsunny Avatar asked May 19 '15 04:05

cytsunny


2 Answers

It appears that you are using a URL instead of the local file path.

For example

include('http://example.com/css/styles.css');

will produce your error but the following should not

include(public_path().'css/styles.css');
like image 58
GeorgeQ Avatar answered Sep 23 '22 10:09

GeorgeQ


if you are using multiple template i will suggest you to create multiple style views which contain just css and you can include them with blade @include

style1.blade.php
style2.blade.php

in styles just put css code

<style>
    .content-of-my-css {
        //content of my css
    }
    // more css
</style>

in master.blade.php layout

<html>
  <head>@include('style1')</head>
</html>

if it is dynamic you can pass style parameter

@include($style)
like image 45
umefarooq Avatar answered Sep 23 '22 10:09

umefarooq