Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
to be logged every time I call the script from[debug] GET "/" [debug] Routing to a callback [debug] 200 OK (0.007915s, 126.342/s) [debug] GET "/get_status"
Thanks for helping!#!/usr/bin/perl use Mojolicious::Lite; plugin 'HTMLTemplateProRenderer'; use Mojo::JSON qw(decode_json encode_json); use HTML::Template; use Data::Dump 'pp'; # dbh attribute app->attr(dbh => sub { my $c = shift; # I set a connection to the DB my $dbh = ...; # Passing connections in a hashref my $pass_dbh = {'dbh' => $dbh }; return $pass_dbh; }); any '/' => sub { my $c = shift; # Load Main Template $c->render( template => 'main', ); # Cant get this to show on the main template. $c->stash( title => ' This is the text for the title' ); }; get '/get_status' => sub { my $c = shift; my $get_update = $c->req->query_params->param('update'); # SQL goes here - this code is only for showing my logic my $data = (<<SQL); SELECT ... SQL # Load value into Main template, # but I cant get the results to display on the template. $c->render( template => 'main', ); # this is the tag in the template <TMPL_VAR NAME="result"> $c->stash( result => ' This is the result for testing' ); # I also return json from the sql query results, called from ajax # and it works fine. return $c->render(json => $data ); }; app->start;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loading values into template using Perl and Mojolicious::Lite
by Corion (Patriarch) on Mar 31, 2017 at 18:11 UTC | |
by Anonymous Monk on Mar 31, 2017 at 18:30 UTC | |
by Corion (Patriarch) on Mar 31, 2017 at 18:32 UTC | |
by Anonymous Monk on Mar 31, 2017 at 18:52 UTC | |
by Corion (Patriarch) on Mar 31, 2017 at 19:07 UTC | |
|