Dancer 插件加载模板
如何从不在“app/views”目录中的 Dancer::Plugin 加载模板而不更改视图默认目录?
这不起作用/它将默认视图路径添加到文件路径/:
package Dancer::Plugin::MyPlugin;
use Dancer ':syntax';
use Dancer::Plugin;
any '/test' => sub {
template '/path_to_template/test.tt' => {
};
};
register_plugin;
1;
How can I load a template from a Dancer::Plugin which is not in 'app/views' directory without changing views default directory?
This isn't working /it adds the default views path to the file path/:
package Dancer::Plugin::MyPlugin;
use Dancer ':syntax';
use Dancer::Plugin;
any '/test' => sub {
template '/path_to_template/test.tt' => {
};
};
register_plugin;
1;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以调用
engine
来获取Dancer::Template
对象并调用其render
方法,例如:然后,将渲染的内容返回到默认布局,调用
apply_layout
:You could call
engine
to get theDancer::Template
object and call itsrender
method, e.g.:Then, to return the rendered content in the default layout, call
apply_layout
:目前,我认为您需要在模板调用之前设置
views
设置,然后再将其更改回来,例如:但是,这很丑陋。
我认为
template
关键字接受system_path
选项是有意义的,就像send_file
那样,所以你可以说,例如:我已为此提出了一个问题,并将考虑在下一个版本中实现它:https://github.com/sukria/Dancer/issues/645
(披露:我是 Dancer 开发团队的一员)
Currently, I think you'd need to set the
views
setting before the template call, then change it back afterwards, for instance:That, however, is ugly.
I think it would make sense for the
template
keyword to accept asystem_path
option, much likesend_file
does, so you could say, e.g.:I've raised an issue for this, and will look in to getting it implemented for the next release: https://github.com/sukria/Dancer/issues/645
(Disclosure: I'm part of the Dancer dev team)