Skip to content

Instantly share code, notes, and snippets.

@stnvh
Created July 20, 2015 15:02
Show Gist options
  • Save stnvh/f84eb78a1d9118a90d8e to your computer and use it in GitHub Desktop.
Save stnvh/f84eb78a1d9118a90d8e to your computer and use it in GitHub Desktop.
Livereload helper for SilverStripe
<?php
/**
* Put {$Livereload} just before the end of the closing body tag
*/
class LivereloadProvider implements TemplateGlobalProvider {
public static function get_template_global_variables() {
return array(
'OnLocalMachine' => 'on_local_machine',
'ServerAddress' => 'server_address',
'Livereload' => 'livereload'
);
}
public static function on_local_machine() {
return defined('GLOBAL_ENVIRONMENT_TYPE') || Director::isDev();
}
public static function server_address() {
return $_SERVER['SERVER_ADDR'];
}
public static function livereload() {
$out = HTMLtext::create();
$out->value = self::on_local_machine() ? sprintf('<script src="http://%s:35729/livereload.js"></script>',
self::server_address()
) : '';
return $out;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment