Welcome Guest, Not a member yet? Register   Sign In
Dynamic CSS -> Passing vars
#1

[eluser]CappY[/eluser]
Hello... I need for my project to load some external TTFs. I want to do it in CSS. But how can I pass vars to there ? I have fonts paths' in MySQL db. I have been tested
Code:
<? foreach ($fonts as $font): ?>
<link rel="stylesheet" type="text/css" href="/img/style.php?font=<?=$font->font?>" media="screen"/>
<? endforeach; ?>

But I reload CSS for every single font. And I need that pages just for few pages and just some controllers takes data for that fonts, and I get that I have no defined var $fonts.

so Question is :
Any easier way to pass variables from controller to CSS?
#2

[eluser]InsiteFX[/eluser]
jQuery!

InsiteFX
#3

[eluser]CappY[/eluser]
Can you be more specific ? Thank you ! Smile
#4

[eluser]John_Betong[/eluser]
 
This may be useful and is a start.

The script passes a $_GET value parameter to the stylsheet. The value parameter is tested and changes the body background color.

Code:
<html>
<head>
  ...
  ...
  <?php $mode = time() % 6; /* returns value 0..5 */ ?>

  <link rel="stylesheet" type="text/css" href="style_test.php?value=<?php echo $mode;?>;" media="screen" />
  ...
  ...
</head>
<body>
 
 
 
// style_test.php
Code:
<?php

header("Content-type: text/css;charset:UTF-8");

$mode = $_GET['value'];
switch($mode)
{
  case 0: $bg = 'f00'; break;
  case 1: $bg = 'fff'; break;
  case 2: $bg = '0f0'; break;
  case 3: $bg = 'ff0'; break;
  case 4: $bg = '00f'; break;
  case 5: $bg = '0ff'; break;
}
?>
  body {background:#<?php echo $bg;?> none;color:#900}
 
 
 
#5

[eluser]InsiteFX[/eluser]
See this article!

Embedding PHP In CSS

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB