NAME

Mojolicious::Plugin::UniqueTagHelpers - Mojolicious Plugin to use unique javascript and stylesheet links.

SYNOPSIS

# Mojolicious
$self->plugin('UniqueTagHelpers');

# Mojolicious::Lite
plugin 'UniqueTagHelpers';

DESCRIPTION

Mojolicious::Plugin::UniqueTagHelpers is a HTML tag helpers for javascript and stylesheet allowing multiple include in templates.

HELPERS

stylesheet_for

@@ index.html.ep
% layout 'default';
% stylesheet_for 'header' => 'css/main.css';
...
% include 'someblock'

@@ someblock.html.ep
...
% stylesheet_for 'header' => 'css/main.css';

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
    <head>
        <title>MyApp</title>
        %= stylesheet_for 'header';
    </head>
    <body>
        <%= content %>
    </body>
</html

This example generate only one link to css/main.css:

<!DOCTYPE html>
<html>
    <head>
        <title>MyApp</title>
        <link href="css/main.css" rel="stylesheet" />
    </head>
    <body>
    </body>
</html>

javascript_for

@@ index.html.ep
% layout 'default';
% javascript_for 'footer' => 'js/main.js';
...
% include 'someblock'

@@ someblock.html.ep
...
% javascript_for 'footer' => 'js/main.js';

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
    <head>
        <title>MyApp</title>
    </head>
    <body>
        <%= content %>
        %= javascript_for 'footer';
    </body>
</html

This example generate only one link to js/main.js:

<!DOCTYPE html>
<html>
    <head>
        <title>MyApp</title>
    </head>
    <body>
        <script src="js/main.js"></script>
    </body>
</html>

SEE ALSO

Mojolicious, Mojolicious::Guides, Mojolicious::Plugin::TagHelpers, http://mojolicio.us.