如何在不更改 View 默认目录的情况下从不在“app/views”目录中的 Dancer::Plugin 加载模板?
这不起作用/它将默认 View 路径添加到文件路径/:
package Dancer::Plugin::MyPlugin;
use Dancer ':syntax';
use Dancer::Plugin;
any '/test' => sub {
template '/path_to_template/test.tt' => {
};
};
register_plugin;
1;
最佳答案
你可以调用 engine
来获取 Dancer::Template
对象并调用它的 render
方法,例如:
my $template_engine = engine 'template';
my $content = $template_engine->render('/path/to/template.tt', { 'name' => 'value' });
然后,要在默认布局中返回呈现的内容,请调用 apply_layout
:
return $template_engine->apply_layout($content);
关于perl - Dancer 插件加载模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7344425/