引数を指定した値が奇数場合は真とする(BlockCondTest02)

構成

$MT_DIR/
|__ plugins/
|  |__ BlockCondTest02/
|     |__ config.yaml
|     |__ lib/
|     |  |__ BlockCondTest02
|     |      |__ Tag.pm
|     |__ lib/
|     |  |__ block.mtblockcondiftest02.php
 
 

ソース

config.yaml

# 詳細
id: BlockCondTest02
key: BlockCondTest02
name: BlockCondTest02
version: 1.0
description: コンディショナルタグテスト
author_name: プラグイン作者
author_link: http://www.example.com/about/
doc_link: http://www.example.com/docs/
 
# タグ定義
tags:
    # ブロックタグ
    block:
        # コンディショナルタグ
        BlockCondIfTest02?: $BlockCondTest02::BlockCondTest02::Tag::_hdlr_block_cond
 
 
 

lib/BlockCondTest02/Tag.pm

package BlockCondTest02::Tag;
 
use strict;
 
# BlockCondTest02の処理
sub _hdlr_block_cond{
 
    # 引数を取得
    my ($ctx, $args, $cond) = @_;
 
     # 値を設定
    my $num = $args->{num} || 0;
 
    my $res;
    if($num % 2 == 1){
        $res = 1;
    }else{
        $res = 0;    
    }
 
    # 返却
    return $res;
}
 
1;
 
 

php/block.mtblockcondiftest02.php

<?php
function smarty_block_mtblockcondiftest02($args, $content, &$ctx, &$repeat){
 
    // 引数を取得
    $count = 0;
    if(isset($args['num'])){
        $count = intval($args['num']);
    }else{
        $count = 1;
    }
 
    // チェック
    if(!isset($content)){
 
        // 奇数チェック
        $res = false;
        if(($count % 2) == 1){
            $res = true;
        }
        return $ctx->_hdlr_if($args, $content, $ctx, $repeat, $res);
 
    }else{
        return $ctx->_hdlr_if($args, $content, $ctx, $repeat);
    }
}
?>
 
 




最終更新:2012年03月10日 21:34