Search code examples
perltemplatesmojolicious

How to render a template outside of a web request in Mojolicious?


Is there a way to use the Mojolicious rendering engine to render a template outside of a web request?


Solution

  • yes

    use Mojolicious::Renderer;
    
    my $renderer = Mojolicious::Renderer->new;
    
    push @{renderer->paths}, '/path/to/your/templates';
    
    my $template = $renderer->get_data_template({
        template       => 'foo/bar',
        format         => 'html',
        handler        => 'epl'
    });