in reply to Re^5: Mojolicious with Template Toolkit
in thread Mojolicious with Template Toolkit
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.
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Mojolicious with Template Toolkit
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 |