I set up .htaccess url rewrite and put the following code in there.
- Code: Select all
RewriteRule (.*/.*\.css)$ ./parse_file.php?file=$1 [NC]
And in parse_file.php I mainly have the following code
- Code: Select all
* The main page of the system
// Requiring TWIG (Template Engine) http://twig.sensiolabs.org/
// Including our definitions
// Including the error management system
// Initiating the error object here as it is required in user.php
$error = new error_handling();
// Including the user management system
// Initiating the required classes
$user = new user();
// Setting the default location of the template directories
$tpl_loc = './templates/' . $user->style;
// Retrieving the file we are supposed to be parsing (css mainly)
$file = (isset($_GET['file'])) ? $_GET['file'] : null;
// Validating the file
if(!is_file($tpl_loc . '/styles/' . $file))
// Making sure we are not gracing the errors
$error->error($user->lang('404'), $user->lang('FILE_NOT_FOUND'), ERROR_FATAL);
// Setting the TWIG loader resource
$loader = new Twig_Loader_Filesystem($tpl_loc . '/styles/');
// Setting the TWIG environment
$twig = new Twig_Environment($loader);
// The replacement array
$replacements = array('CSS_URL' => $tpl_loc . '/styles/',
'IMG_URL' => $tpl_loc . '/images/'
// Rendering the file
It seems to work, it redirects the CSS to parse_file.php, but the CSS doesn't get parsed through TWIG and doesn't get returned. When I view the generated source code and click on a stylesheet, I see the following error:
<b>Fatal error</b>: Uncaught exception 'Twig_Error_Loader' with message 'Unable to find template "templates/default/styles/menu.css" (looked into: ./templates/default/styles).' in C:\xampp\htdocs\www\cms\twig\Loader\Filesystem.php:202
#0 C:\xampp\htdocs\www\cms\twig\Loader\Filesystem.php(138): Twig_Loader_Filesystem->findTemplate('templates/defau...')
#1 C:\xampp\htdocs\www\cms\twig\Environment.php(265): Twig_Loader_Filesystem->getCacheKey('templates/defau...')
#2 C:\xampp\htdocs\www\cms\twig\Environment.php(323): Twig_Environment->getTemplateClass('templates/defau...', NULL)
#3 C:\xampp\htdocs\www\cms\twig\Environment.php(292): Twig_Environment->loadTemplate('templates/defau...')
#4 C:\xampp\htdocs\www\cms\parse_file.php(57): Twig_Environment->render('templates/defau...', Array)
thrown in <b>C:\xampp\htdocs\www\cms\twig\Loader\Filesystem.php</b> on line <b>202</b><br />
The thing is: the file path where TWIG is looking for the files are correct, the stylesheet IS there but TWIG is having problems finding it for some reason... and the stack trace seems to show that it is using the correct parameters, but can't tell for sure since it has being cut off.
Any help? I guess I could write a special templating class simply for stylesheets but before I do that I'm going to try and get it to work with TWIG. Reason I need this (right now the project is fresh) is that I'm going to have some values being retrieved from the database and used in CSS.
I don't want to insert the stylesheets into the document hard-coded because I have three different stylesheets (separated for organizational purposes) and combining them would defeat the organization and make each file really big.