Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Passing a value to Mojo::Template template

by haukex (Archbishop)
on Apr 14, 2021 at 16:56 UTC ( [id://11131288]=note: print w/replies, xml ) Need Help??


in reply to Passing a value to Mojo::Template template

The data for the variables should be in a single hash. $mt->render_file('myfile.html.ep', { data => $data, test => $code } ) works for me.

Replies are listed 'Best First'.
Re^2: Passing a value to Mojo::Template template
by Anonymous Monk on Apr 14, 2021 at 17:07 UTC
    Thats great and made me think about another possibility, if I had multiple values as:
    { data => $data, test => $code, color => 'blue', name => $names, ... }

    Could I combine all of it into one variable and than pass to "$mt->render_file()"?

    Thank you!
      Could I combine all of it into one variable and than pass to "$mt->render_file()"?

      I'm not sure I fully understand the question... do you mean something like the following (which works too)? If not, please provide more context, preferably in the form of an SSCCE (see also How do I post a question effectively?).

      my %vars = ( data => $data, test => $code, color => 'blue' ); print $mt->render_file( 'myfile.html.ep', \%vars );
        Sorry for the short code sample there, but you did answer it, thank you. The only downside of it, is that it will add more complexity to extract the data to the template file, right?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131288]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found