Mojolicious sharing of form element name between Perl and the template

138 views Asked by At

I'm new at using Mojolicious and therefore I apologize if this is a basic question but I looked around and couldn't find a good way to do it.

I would like to know what's the best strategy to share the name of form parameters between the Perl code (to be used in param('element') and a template (to be used in say INPUT name="element" ...>. Is there a way to define 'element' somewhere so that it can be used in both the Perl side and the template side? A super global variable?

Thanks in advance!

1

There are 1 answers

1
Logioniz On

if i understand you correct then stash - is answer for your question.

https://metacpan.org/pod/Mojolicious::Controller#stash

Example. In controller you have such code:

sub action {
 my $c = shift;
 $c->stash(name_of_param => $c->param('name_of_param'), another_param => $c->param('another_param'));
 $c->render;
}

In template:

<h1><%= $name_of_param %></h1>
<h2><%= $another_param %></h2>

I think that more good way not exist.