BlockTest05
構成
$MT_DIR/
|__ plugins/
| |__ BlockTest05/
| |__ config.yaml
| |__ lib/
| | |__ BlockTest05
| |__ Plugin.pm
ソース
config.yaml
id: block05
key: BlockTest05
name: BlockTest05
tags:
block:
BlockTest05: $BlockTest05::BlockTest05::Plugin::hdlr_func05
function:
FunctionTest05: $BlockTest05::BlockTest05::Plugin::hdlr_func05a
lib/BlockTest03/Plugin.pm
package BlockTest05::Plugin;
use strict;
use MT::Page;
sub hdlr_func05{
# 引数を取得
my ($ctx, $args, $cond) = @_;
# コンテキストよりbuilderを取得
my $builder = $ctx->stash('builder');
# トークンを取得
my $tokens = $ctx->stash('tokens');
# 初期化
my $html = '';
# 条件変数定義
my $items;
my $arg;
# 抽出、表示条件定義
$items->{status} = '2';
$arg->{direction} = 'descend';
# ウェブページの情報を取得
my $iter = MT::Page->load_iter($items, $arg);
my $html;
$html .= "<br /><h1>start</h1><br />";
while(my $entry = $iter->()){
# ローカルスコープへ値を一時的に設定
local $ctx->{__stash}{'myplugin::entry'} = $entry->title;
# ブロックタグを構築、失敗時はエラー
my $out = $builder->build ($ctx, $tokens, $cond);
return $ctx->error ($builder->errstr) if !defined $out;
# 連結
$html .= $out;
}
$html .= "<br /><h1>end</h1><br />";
# 値返却
return $html;
}
sub hdlr_func05a{
# 引数を取得
my ($ctx, $args) = @_;
# 取得した値を返却
my $entry = $ctx->stash('myplugin::entry');
return $entry;
}
1;
最終更新:2012年01月25日 01:08