[TYPO3] Random CSS at every pageview

Dmitry Dulepov [typo3] dmitry at typo3.org
Sat Feb 16 11:41:08 CET 2008


Edwin Blokker wrote:
> Hi Benjamin,
> 
> Thanks, but that's not what I want to do. I want to load a random CSS 
> file on every FE pageview, without the user doing anything.
> 
> Does anyone have any suggestions?

If you know PHP, you can do it this way:

includeLibs.user_randomCSS = fileadmin/randomcss.php
page.10.headerData = USER_INT
page.10.headerData.userFunc = user_randomCSS

And in randomCSS.php:

<?php
function user_randomCSS() {
	$cssfiles = array();
	$cssdir = 'fileadmin/mycssfiles';
	$dir = opendir(PATH_site . $cssdir); 
	while (false != ($f = readdir($dir))) {
		if (preg_match('/\.css$', $f)) {
			$cssfiles[] = $f;
		}
	}
	closedir($dir);
	return '<link rel="stylesheet" type="text/css" href="fileadmin/mycssfiles/' .
		 $cssfiles[rand(0, count($cssfiles) - 1] . '" />';
}
?>


Totally untested :)

-- 
Dmitry Dulepov
TYPO3 core team
Web: http://typo3bloke.net/
Skype: callto:liels_bugs
"Nothing is impossible. There are only limits to our knowledge"


More information about the TYPO3-english mailing list