Recently in MT Category

MT3系(たぶん4系でもそのまま使える)のダイナミックパブリッシング用の条件タグの実装方法を次にメモする。
まず、下記のテンプレートは『MovableType上級カスタマイズ術』からの引用である。

<?php
function smarty_block_条件タグ($args, $content, &$ctx, &$repeat) {
    if( $issset($content) ) {
        // 条件判断処理
        return $ctx->_hdlr_if($args, $content, $ctx, $repeat, $retcode);
    } else {
        return $ctx->_hdlr_if($args, $content, $ctx, $repeat);
    }
}
?>

これだと$argsにMTの変数を渡せないけど、どうすればいいのかわからない。

次の例では、<$SampleImage$>があるかないかで、出力する内容を分岐させる例である。


<MTIfNonEmpty tag="SampleImage">
<img src="<$SampleImage$>" alt="" width="32" />
<MTElse>
<img src="/noimage.gif" alt="" width="32" />
</MTElse>
</MTIfNonEmpty>


MTIfNonEmpty はtagに与えた変数が空であるかどうかを判断し、"空である場合"に処理を続ける。また、
MTElseで"空の場合"の処理を記述できる。

MTのテンプレートを一部コメントアウトするには、
<MTIgnore>タグを使えばよい。


<blockquote><MTIgnore> コメントアウトしたい内容 </MTIgnore></blockquote>


コメントアウトしたい内容に <!-- や --> が含まれている場合も問題なく使用できる。

About this Archive

This page is a archive of recent entries in the MT category.

JavaScript is the previous category.

parser is the next category.

Find recent content on the main index or look in the archives to find all content.