Reputation: 462
I have a post route which is returning params for use in a specific template (actions.tt). Within that template, I'm loading a div (using jQuery) with a view (dirmain.tt) of a directory using the DirectoryView plugin. My problem is that I need to pass a param to the DirectoryView template before rendering the main template (action.tt).The param (dev) needs to be included in the the Directory listing.
Perl portion:
Use Dancer;
....
post "/" => sub {
template 'actions.tt', {
'dev' => param('dev'),
};
Templates:
actions.tt
....
<div id="dir">
<script type="text/javascript">
$('#dir').load('/files/[% dev %]');
</script>
</div>
....
dirmain.tt
....
how do I pass [% dev %] here before the action.tt is rendered by the browser?
....
Would using a hook of some sort fulfill this? Your help is much appreciated. Thanks!
Upvotes: 1
Views: 496
Reputation: 21
params is a function that delivers a hash, so params("dev") won't get you anything. This is better:
template 'actions.tt', {
'dev' => param->{dev},
}
but in Dancer, some variables like params, request and session are exported by default in the templates. So you can leave the {} after 'template' empty and use this in your template:
$('#dir').load('/files/[% params.dev %]');
Upvotes: 2