in reply to Re^4: Mojolicious with Template Toolkit
in thread Mojolicious with Template Toolkit
Mojolicious offers Helpers of Mojolicious::Guides::Tutorial which are functions which you setup during startup. I am not sure if this is a good way, but I would do something like:
use Mojo::Base 'Mojolicious'; # This method will run once at server start sub startup { my $self = $_[0]; $self->app->config( hypnotoad => { listen => ['http://'.$SERVER_ADDRESS.':'.$SERVER_PORT] } ); my $DOCUMENT_ROOT = '...'; $self->helper(document_root => sub { $DOCUMENT_ROOT }); # I also add a logger object my $logger = Mojo::Log->new; $self->helper(applog => sub { $logger }); ... }
And at any route endpoint (in its own separate file):
use Mojo::Base 'Mojolicious::Controller'; sub logout { my $c = $_[0]; my $log = $c->applog; my $dr = $c->document_root; ... $c->render(...) return 1; }
There is also Mojolicious::Plugin::DefaultHelpers with some helpers before reinventing the wheel
FWIW, the template system I use is Text::Xslate via MojoX::Renderer::Xslate. It's surely idiosyncratic and the language associated with it is aptly named Kolon! I *think* I heard choroba saying that it was quite fast when I was looking around. And I use it for 3 years now, quite happy and with colon painless.
bw, bliako
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Mojolicious with Template Toolkit
by hippo (Archbishop) on Mar 08, 2023 at 14:42 UTC | |
by marto (Cardinal) on Mar 08, 2023 at 15:52 UTC | |
by hippo (Archbishop) on Mar 08, 2023 at 17:14 UTC | |
by marto (Cardinal) on Mar 08, 2023 at 17:42 UTC |