my $DOCUMENT_ROOT = '...';

This line is precisely the problem. In other frameworks I do not need to set the document root explicitly by hand inside the application. The webserver does this and the application just picks it up through $ENV{DOCUMENT_ROOT}. The document root will necessarily vary depending upon how and where the app is deployed (eg. dev vs production) so I don't want anything inside the app itself to explicitly specify a document root with an absolute path.

I'm getting the impression that Mojolicious is unable to tell where its own document root is, which seems odd. Hopefully that's just a misconception on my part. The closest thing so far which works is this:

use Cwd; $ENV{DOCUMENT_ROOT} //= getcwd . '/..'; plugin 'tt_renderer' => { template_options => { INCLUDE_PATH => [ "$ENV{DOCUMENT_ROOT}/../templates/lib", ... ], ENCODING => 'utf8', } };

But it's far from elegant and relies on the application being one level below the docroot.

Update: Actually, thinking further there isn't really any need for the app to be under the docroot at all. I suppose it could be placed outside the docroot in a fixed position with respect to the templates dir and could load it from there, so INCLUDE_PATH would just be ../templates/lib for instance. That seems a better compromise and will also work for @INC.


🦛


In reply to Re^6: Mojolicious with Template Toolkit by hippo
in thread Mojolicious with Template Toolkit by hippo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.