0

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!

G. Cito
  • 6,210
  • 3
  • 29
  • 42
Jerome Provensal
  • 931
  • 11
  • 22

1 Answers1

1

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.

Logioniz
  • 891
  • 6
  • 15