Scarwolf Scarwolf - 1 year ago 81
PHP Question

Generate CSS classes from database?

It's possible to define a main color and a secondary color (hex-codes) in my application, those are saved to the db.

The secondary color for example is used for links. I don't want to say

<a href="#" style="color: $fromDatabase">Text</a>
but instead
<a href="#" class=secColor>Text</a>
has something like

.secColor {
color: $fromDatabase;

I'm using Laravel btw.

Answer Source

You can include a .php file as a css by using following code:


   <link rel="stylesheet" href="style.php">
<!-- stuff goes here -->


  header("Content-type: text/css");
//DB Query
   color: <?php echo $fromDatabase;?>