[Koha-bugs] [Bug 31786] Sub template->param($var) should return the value

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Wed Oct 19 00:36:22 CEST 2022


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31786

David Cook <dcook at prosentient.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dcook at prosentient.com.au

--- Comment #4 from David Cook <dcook at prosentient.com.au> ---
(In reply to Marcel de Rooy from comment #3)
> (In reply to Jonathan Druart from comment #2)
> > What is the context? Why don't you use CGI->param? :)
> 
> See description too. If earlier code like C4/Auth already pushed info into
> the template object, it would be nice to read it back later (instead of
> requerying etc.). Yes, we can access {VARS} but that looks like a bad
> practice.
> In such a case CGI::param might not be in the picture.

In frameworks like Catalyst and Mojolicious, the controller has a "stash"
method which provides getting/setting of values to pass to the template. I've
certainly used it for both getting and setting in both frameworks.

Catalyst:
$c->stash->{foo} = $bar;
$c->stash( { moose => 'majestic', qux => 0 } );
$c->stash( bar => 1, gorch => 2 ); # equivalent to passing a hashref

Mojolicious:
my $name = $c->stash('name');
$c->stash(text => "Hello $name");

https://metacpan.org/pod/Catalyst#$c-%3Estash
https://docs.mojolicious.org/Mojolicious/Guides/Tutorial#Stash-and-templates
https://mojolicious.io/blog/2017/12/02/day-2-the-stash/

So returning a value from $template->param() does sound reasonable.

However... I thought that we were moving away from $template->param() and to
$template->{VARS} in general. (Although I don't see a Coding Guideline that
says that.)

-- 
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.


More information about the Koha-bugs mailing list