NAME
Mojolicious::Plugin::JSUrlFor - "url_for" for javascript
SYNOPSIS
# Mojolicious
$self->plugin('JSUrlFor');
# Mojolicious::Lite
plugin 'JSUrlFor';
# In you application
my $r = $self->routes;
$r->get('/messages/:message_id')->to('messages#show')->name('messages_show');
# In your layout template
<head>
<%= js_url_for%>
</head>
# In your javascript
$.getJSON( url_for( 'messages_show', {message_id: 123} ), params, function() { ... } )
DESCRIPTION
I like Mojlicious routes. And one feature that I like most is that you can name your routes. So, you can change your routes without rewriting a single line of dependent code. Of course this works if you use routes names in all of your code. You can use routes name everywhere except... javascript. But with <LMojolicious::Plugin::JSUrlFor> you can use routes names really everywhere.
Mojolicious::Plugin::JSUrlFor contains only one helper that add ulr_for function to your client side javascript.
HELPERS
js_url_for
In templates <%= js_url_for %>
This helper will add url_for function to your client side javascript.
In "production" mode this helper will cache generated code for javascript "url_for" function
METHODS
Mojolicious::Plugin::JSUrlFor inherits all methods from Mojolicious::Plugin and implements the following new ones.
register
$plugin->register;
Register plugin in Mojolicious application.