Created
July 20, 2015 15:02
-
-
Save stnvh/f84eb78a1d9118a90d8e to your computer and use it in GitHub Desktop.
Livereload helper for SilverStripe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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