I wanted to display the count of three database tables: Data
, Meta
and Type
.
So naturally I stash those values, and render them (using Mojolicious::Lite
).
$c->stash(data => $count_data,
meta => $count_meta,
type => $count_type,
);
$c->render(template => 'tblcount');
Turns out, that data
is a reserved keyword in the stash.
The observed effect was, that after rendering only the value in $count_data
will be shown... ignoring the template completely. Also no errors.
This was kind of hard to debug (it costed like an hour or so of my sanity). Also I'm sure I'm not the first one, who is accidentally misusing the data keyword (or any of the other keywords).
My question: Is there any safe way of passing variables with arbitrary names to the template? Or do I just have to life with this possible clash of names?
The stash takes arbitrary structures, so you can store a hash of arbitrary data.
$c->stash(stuff => {data => $count_data, ...});
Then using $stuff->{data}
in the template.