Welcome Guest, Not a member yet? Register   Sign In
URL Helper not found in CSS
#1

Morning & Afternoon all,

I've got a style sheet called custom.css.php that contains this:

<?php header("Content-type: text/css; charset: UTF-8"); ?>

body,
html {
   width: 100%;
   height: 100%;
}

... more styling stuff ...

.archive-banner {
   background: url(<?= base_url("assets/media/images/hero-banner.jpg"); ?>) no-repeat center center;
   background-size: cover;
}



When I go to any page however, the formatting is all a bit odd. If I view the source of the style sheet then I can see this error:

.archive-banner {
   background: url(<br />
<b>Fatal error</b>:  Call to undefined function base_url() in <b>/var/www/public/projects/ida-ci/assets/styles/custom.css.php</b> on line <b>47</b><br />


I'm assuming that this error means that the URL helper isn't getting pulled into the custom.css.php file. But my autoload.php contains this: 

$autoload['helper'] = array('url');

Do I need to explicitly specify that the style sheet needs to include this helper too? Any ideas would be greatly appreciated. Cheers!
Reply
#2

You can't embed php code inside a css file.
Reply
#3

(This post was last modified: 03-08-2017, 03:01 AM by mohnjatthews.)

(03-07-2017, 10:01 AM)Wouter60 Wrote: You can't embed php code inside a css file.

According to these Stack Overflow pages you can:

 - http://stackoverflow.com/questions/53389...ode-in-css
 - http://stackoverflow.com/questions/19338...e-css-file
 - http://stackoverflow.com/questions/10333...tyle-sheet

Or did you mean that it's not possible in CodeIgniter?
Reply
#4

(03-07-2017, 05:52 AM)mohnjatthews Wrote: Do I need to explicitly specify that the style sheet needs to include this helper too?

What you have is just a random PHP script ... it can't use the CI helpers because you're not running it through CI in the first place.

(03-07-2017, 10:01 AM)Wouter60 Wrote: You can't embed php code inside a css file.

It's not a CSS file, it's a PHP script that happens to generate CSS and have '.css' in the middle of its name.
Reply
#5

(03-08-2017, 03:56 AM)Narf Wrote: What you have is just a random PHP script ... it can't use the CI helpers because you're not running it through CI in the first place.

Understood. Would you be able to point me towards some documentation to help me here?

(03-08-2017, 03:56 AM)Narf Wrote: It's not a CSS file, it's a PHP script that happens to generate CSS and have '.css' in the middle of its name.

That's why I said style sheets in an attempt to make this bit clearer. Sorry for any confusion. The ".css" in the middle is so PHP storm picks up on the syntax highlighting.
Reply
#6

CSS Variables with PHP

Read it and the variables.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(This post was last modified: 03-13-2017, 10:25 AM by spjonez.)

This is generally a bad idea as the client will not cache the output of your files. It's better to use a build step like Less if you need to use variables. You shouldn't need to use base_url in CSS paths just use a relative path.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB