BlockTest04
構成
$MT_DIR/
|__ plugins/
| |__ BlockTest04/
| |__ config.yaml
| |__ lib/
| | |__ BlockTest04
| |__ Plugin.pm
ソース
config.yaml
id: block04
key: BlockTest04
name: BlockTest04
tags:
block:
BlockTest04: $BlockTest04::BlockTest04::Plugin::hdlr_func04
function:
FunctionTest04: $BlockTest04::BlockTest04::Plugin::hdlr_func04a
lib/BlockTest03/Plugin.pm
package BlockTest04::Plugin;
use strict;
use MT::Page;
sub hdlr_func04{
# 引数を取得
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;
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;
}
# 値返却
return $html;
}
sub hdlr_func04a{
# 引数を取得
my ($ctx, $args) = @_;
# 取得した値を返却
my $entry = $ctx->stash('myplugin::entry');
return $entry;
}
1;
最終更新:2012年01月25日 01:10