bli*_*iof 2 perl plugins 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;
Run Code Online (Sandbox Code Playgroud)
您可以调用engine来获取Dancer::Template对象并调用其render方法,例如:
my $template_engine = engine 'template';
my $content = $template_engine->render('/path/to/template.tt', { 'name' => 'value' });
Run Code Online (Sandbox Code Playgroud)
然后,要返回默认布局中渲染的内容,请调用apply_layout:
return $template_engine->apply_layout($content);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
632 次 |
| 最近记录: |