指定回数分出力(BlockTest02)
構成
$MT_DIR/
|__ plugins/
| |__ BlockTest02/
| |__ config.yaml
| |__ lib/
| | |__ BlockTest02
| | |__ Tag.pm
| |__ php/
| | |__ block.mtblocktest02.php
ソース
config.yaml
# 詳細情報
id: BlockTest02
key: BlockTest02
name: BlockTest02
version: 1.0
description: ブロックタグテスト
author_name: プラグイン作者
author_link: http://www.example.com/about/
doc_link: http://www.example.com/docs/
# タグ
tags:
# ブロックタグ
block:
BlockTest02: $BlockTest02::BlockTest02::Plugin::hdlr_func02
lib/BlockTest02/Tag.pm
package BlockTest02::Tag;
use strict;
# ブロックタグハンドラ
sub hdlr_func02{
# 引数を取得
my ($ctx, $args, $cond) = @_;
my $builder = $ctx->stash('builder');
my $tokens = $ctx->stash('tokens');
my $loop = $args->{count} || 1;
my $html = '';
for (my $count = 1; $count <= $loop; $count++) {
my $out = $builder->build ($ctx, $tokens, $cond);
return $ctx->error ($builder->errstr) if !defined $out;
$html .= $out;
}
return $html;
}
1;
php/block.mtblocktest02.php
<?php
function smarty_block_mtblocktest02($args, $content, &$ctx, &$repeat){
// ローカル変数エリア
$localvars = array('mt_blocktest02_counter', 'mt_blocktest02_count');
// 初期化チェック
if(!isset($content)){
// ローカル変数初期化
$ctx->localize($localvars);
// 初期化処理
$_maxCount = 1;
if(isset($args['count'])){
$_maxCount = intval($args['count']);
}else{
$_maxCount = 1;
}
$counter = $_maxCount;
$count = 0;
}else{
// 継続データ取得
$counter = $ctx->stash('mt_blocktest02_counter');
$count = $ctx->stash('mt_blocktest02_count');
}
// 終端チェック
if($count < $counter){
// 変数設定
$ctx->stash('mt_blocktest02_counter', $counter);
$ctx->stash('mt_blocktest02_count', $count + 1);
// 繰り返しON
$repeat = true;
}else{
// ローカル変数開放
$ctx->restore($localvars);
// 繰り返しOFF
$repeat = false;
}
// 返却
return $content;
}
?>
最終更新:2012年03月10日 12:00