Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Mojolicious: Optional placeholder and template name

by frazap (Monk)
on May 17, 2019 at 14:16 UTC ( #11100175=perlquestion: print w/replies, xml ) Need Help??

frazap has asked for the wisdom of the Perl Monks concerning the following question:

I have a small Mojolicious app that display a page
$r->get('/libmap');
And load a libmap.html.ep template in the ./template folder.

This file uses js files that are in the ./public folder.

I would add a locale in the url:  ....:3000/fr/libmap, without having any other change in the path of the template or public folders,

I tried

$r->get('/:loc/libmap')->to(template => 'libmap', loc=> 'en');
but it fails with Page not found...

What am I missing ?

Thanks!

Edit: I have a utils.js file that is searched in public/fr/utils.js folder instead of public/utils.js folder.

That were the problem is... How can I keep on with having all my js files in ./public and not in public/fr, public/en ... ?

Replies are listed 'Best First'.
Re: Mojolicious: Optional placeholder and template name
by trippledubs (Deacon) on May 19, 2019 at 13:13 UTC

    If you run your site under morbo, the debug output should have some information on why your template is not rendering. The default error page under morbo is also helpful.

    When you reference a link in the final html that is rendered, it will be relative to public. So a link like src=/blah.js means search for it in the public directories of the app, by default /public.

    Update: Fix link

    Second Update: Static files are served in sequential order from the array  $app->static->paths.

      Thanks for helping. I should be more specific:

      The template common_js.html.ep (in ./templates) that load the js files is
      <script src="monomapdata.js" type="text/javascript"></script> <script src="monomap.js" type="text/javascript"></script> <script src="utils.js" type="text/javascript"></script>
      This works when I call http:// .... :3000/libmap, but not with :3000/fr/libmap If I change the src values to
      <script src="../monomapdata.js" type="text/javascript"></script> <script src="../monomap.js" type="text/javascript"></script> <script src="../utils.js" type="text/javascript"></script>
      :3000/fr/libmap works. But is it the right way to do this ?

      Thanks

        Did you try
        <script src="/monomapdata.js" type="text/javascript"></script>
        ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11100175]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2020-12-02 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (47 votes). Check out past polls.

    Notices?