Skip to content

Instantly share code, notes, and snippets.

@niczero
Created April 7, 2017 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niczero/d1f8ba667458cfde7350165f40a42c57 to your computer and use it in GitHub Desktop.
Save niczero/d1f8ba667458cfde7350165f40a42c57 to your computer and use it in GitHub Desktop.
Variant templates driven by env
#!/usr/bin/env perl
use Mojolicious::Lite;
app->mode('development') and app->defaults(variant => 'offline')
if ($ENV{MOJO_MODE} // '') eq 'offline';
get '/' => sub { shift->render(template => 'index') };
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'Value Added';
The value of 'variant' is: <%= stash('variant') // '(nothing)' %>.
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
@@ layouts/default.html+offline.ep
<!DOCTYPE html>
<html>
<head><title><%= '[offline] '. title %></title></head>
<body><%= content %></body>
</html>
@niczero
Copy link
Author

niczero commented Apr 7, 2017

Sometimes you're developing your always-connected app while holed-up in your always-offline mountain retreat. At other times you're on an underground train. Wherever, it can be handy to fall-back to serving cdn files (eg js) from a local cache.

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