Perl Dancer、Dancer::Plugin::DirectoryView、模板工具包和在模板中共享参数
我有一个后路由,它返回用于特定模板(actions.tt)的参数。在该模板中,我使用 DirectoryView 插件加载一个带有目录视图 (dirmain.tt) 的 div(使用 jQuery)。我的问题是,在渲染主模板 (action.tt) 之前,我需要将参数传递给 DirectoryView 模板。参数 (dev) 需要包含在目录列表中。
Perl 部分:
Use Dancer;
....
post "/" => sub {
template 'actions.tt', {
'dev' => param('dev'),
};
模板:
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?
....
使用某种钩子可以实现这一点吗? 非常感谢您的帮助。谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
params 是一个提供哈希值的函数,因此 params("dev") 不会给你任何东西。这更好:
但在 Dancer 中,一些变量(如 params、request 和 session)默认在模板中导出。因此,您可以将“template”后面的 {} 留空并在模板中使用它:
params is a function that delivers a hash, so params("dev") won't get you anything. This is better:
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: