6

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)

1
  • This helped me and could help others that find here from google codingwithstef.com/… Commented Feb 21, 2022 at 17:02

2 Answers 2

9

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');
Sign up to request clarification or add additional context in comments.

1 Comment

Just for the record. You are missing a "/" -> include(public_path().'/css/styles.css'); But +1 for the answer. Worked like a charm.
2

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)

2 Comments

As the css style will as well be used in email preview (which is normal web page) , so in my situation it is better to be kept as css file.
Also, it is <head> instead of <header> in html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.