Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created September 13, 2012 11:50
Show Gist options
  • Select an option

  • Save mattattui/3713822 to your computer and use it in GitHub Desktop.

Select an option

Save mattattui/3713822 to your computer and use it in GitHub Desktop.
Symfony 1.4 versioned stylesheets/css
app:
# ...
resource_version: <?php echo date_create()->format('YmdHis');
<?php
function include_stylesheets_versioned()
{
$response = sfContext::getInstance()->getResponse();
sfConfig::set('symfony.asset.stylesheets_included', true);
$html = '';
foreach ($response->getStylesheets() as $file => $options) {
if ((strpos($file, '?') === false) && (stripos($file, 'http') !== 0) ) {
$file .= '?v='.sfConfig::get('app_resource_version');
}
$html .= stylesheet_tag($file, $options);
}
echo $html;
}
function include_javascripts_versioned()
{
$response = sfContext::getInstance()->getResponse();
sfConfig::set('symfony.asset.javascripts_included', true);
$html = '';
foreach ($response->getJavascripts() as $file => $options) {
if ((strpos($file, '?') === false) && (stripos($file, 'http') !== 0) ) {
$file .= '?v='.sfConfig::get('app_resource_version');
}
$html .= javascript_include_tag($file, $options);
}
echo $html;
}
@edriang

edriang commented Jun 8, 2016

Copy link
Copy Markdown

Excellent Helper! I'll add some clarification about how to implement this for other devs.

In settings.yml you have to configure standard_helpers, not default_modules, like ie:
standard_helpers: [Partial, Cache, glxAsset]
You want to include Partial and Cache, which are the default ones

If you like to do this in a "by template" fashion, you can add this line at the beginning of your layout.php:
<?php use_helper('glxAsset') ?>

How this tips helps others..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment