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

Hi, monks

I can't insert images on my Mojolicious projects. I'm converting my CGI script to Mojo. I'm Mojo newbie yet.

My current app structure is:
myapp |- myapp.pl |- lib | |- MyApp.pm | +- MyApp | +- Model | +- Users.pm |- t | +- login.t +- templates |- layouts | +- default.html.ep |- index.html.ep +- <b>protected.html.ep</b>

It's an example from Mojolicious::Guides::Growing

My questions are:

1. How can I insert an image on protected.html.ep?
2. Where should I store my image files?
3. How <img src=''> should be?


Thanks for help

Replies are listed 'Best First'.
Re: Insert images on Mojolicious website
by beech (Parson) on Aug 21, 2016 at 03:02 UTC

    Images are "static" file so Ctrl+F "static" and find

    |- public # Static file directory (served automatical +ly) | +- index.html # Static HTML file

    So you can add  public/images/foo.jpg and you link to it from  public/foo.html with  src="images/foo.jpg"

    you can access foo.html as http://localhost../foo.html

      So you can add public/images/foo.jpg and you link to it from public/foo.html with src="images/foo.jpg"

      Ok. I see. It's needed create a public DIR on myapp structure

      myapp |- myapp.pl |- lib | |- MyApp.pm | +- MyApp | +- Model | +- Users.pm |- t | +- login.t |- public | +- img | +- foo.jpg +- templates |- layouts | +- default.html.ep |- index.html.ep +- protected.html.ep

      Thanks beech