Rendering Variant

36 views
Skip to first unread message

Stefan Adams

unread,
Feb 19, 2015, 8:59:42 PM2/19/15
to mojolicious
From the Rendering Guide:

$c->render('foo/bar/baz', variant => 'phone');

What's a good way to recognize that the variant => 'phone' variable should be set?

That is, I wouldn't have a route action like this:

get '/' => sub {
  my $c = shift;
  $c->render('foo/bar/baz', variant => 'phone');
};

Because then all user agents would get the phone variant, and then what's the point of a variant?

Instead, one would need something like:

get '/' => sub {
  my $c = shift;
  $c->render('foo/bar/baz', variant => $c->is_mobile ? 'phone' : '');
};

I see that there is a plugin Mojolicious::Plugin::Mobi.  Is that the way to do it?  Use its is_mobile() helper to determine whether or not to set the variant to phone?

sri

unread,
Feb 19, 2015, 9:13:13 PM2/19/15
to mojol...@googlegroups.com

Stefan Adams

unread,
Feb 19, 2015, 10:00:44 PM2/19/15
to mojolicious


On Feb 19, 2015 8:13 PM, "sri" <kra...@googlemail.com> wrote:
>
> http://mojolicio.us/perldoc/Mojolicious/Guides/Routing#Hooks

Ah wonderful! Thank you for pointing that out!

No matter how many times I read the docs I'll never be able to retain it all at once! :)

> --
> sebastian
>
> --
> You received this message because you are subscribed to the Google Groups "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
> To post to this group, send email to mojol...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages