Posted by Wolfgang Reszel on March 1, 2012 at 10:33am
3 followers
| Project: | Zentropy |
| Version: | 7.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Hi,
I created a sub theme which add's a Dev option to temporary disable Drupal's CacheBuster query strings after the stylesheet file name (style.css?XYZ). This is useful for live styling with Espresso or CSSEdit for Mac using their great @override feature.
Mabe it could be included in Zentropy core.
theme-settings.php
$form['zentropy_settings']['zentropy_dev']['zentropy_cachebuster_css'] = array(
'#type' => 'select',
'#title' => t('CachBuster CSS query strings'),
'#description' => t('During theme styling with CSSEdit’s or Espresso’s @override feature, it can be very useful to disable the CacheBuster CSS query strings. (style.css?XYZ)'),
'#default_value' => theme_get_setting('zentropy_cachebuster_css'),
'#options' => array(
'' => t('Add query strings (Drupal default)'),
'all' => t('Always remove query strings'),
'onlyadmin' => t('Remove query strings for logged in admins only'),
),
);template.php
/**
* Implements template_process_html().
*/
// Remove Query Strings from CSS filenames (CacheBuster)
function zentropy_process_html(&$variables) {
global $user, $conf;
if (theme_get_setting('zentropy_cachebuster_css')) {
if (theme_get_setting('zentropy_cachebuster_css') == 'all' || (in_array("administrator",$user->roles) && @$conf['site_offline'] == 0 && !stristr($_GET['q'],'flush-cache'))) {
$variables['styles'] = preg_replace('/\.css\?.*"/','.css"', $variables['styles']);
}
}
}
Comments
#1
Awesome! Absolutely!
Would you mind creating a patch against 7.x-2.0-dev?
I would happily review and commit it, giving you author credits! :)
#2
Okay. I try. I never created a patch before. I hope it works.
#3
Patch applied cleanly, commited in 457ded5.
Thanks! :)
#4
Wolfgang, I've been thinking about this and I love the feature but I don't see why we need to have the option to enable it for admins only. Since this is a development-only feature we assume that performance doesn't matter, I'm going to change this to either on or off.
Comments?
#5
Well, my Drupal projects are often vital projects where I sometimes adjust or enhance the styling on the page which is already online. I don't want the visitors or editors would be forced to reload the stylesheets. So I just have to login as admin for styling without affecting other users and its also faster than enabling this option every time I need it. Previously I had this always hardcoded in my templates and as I decided to always use Zentropy as my base for future projects I thought it would be cool to be optional. Sometimes I need styling when not logged in, so a simple on-off does not fit my needs.
#6
Wolfgang, I understand and will take this into consideration!
PS - The commit is looking nice in your profile page! ;)
#7
@Wolfgang, I gave this some thought and re-enabled the "admin only" option. Commited in dev, release coming later on tonight! :)
#8
Lovely.
This is a nice general solution as well.
<?phpfunction MYTHEME_process_html(&$vars) {
if (variable_get('environment') == 'development' && !stristr($_GET['q'],'flush-cache')) {
$vars['styles'] = preg_replace('/\.css\?.*"/','.css"', $vars['styles']);
}
}
?>
As long as you place these in your settings.local.php files...
$conf['environment'] = 'development';$conf['environment'] = 'production';