ググらずには前へ進めないフロントエンドエンジニアが書く、次はググらなくてもできますように…とメモを残すブログです!

MovableType 文字がN文字以上なら点々を付ける方法!

2011/02/02
⚠️投稿日または最終更新日から12年以上経過している内容です。

ソース

html
<mt:setvarblock name="3ten_flag"><$mt:entrybody strip_linefeeds="1" remove_html="1" count_characters="1" $></mt:setvarblock>
<mt:if name="3ten_flag" gt="200">
    <$mt:entrybody strip_linefeeds="1" remove_html="1" trim_to="200"$>...
<mt:else>
    <$mt:entrybody strip_linefeeds="1" remove_html="1"$>
</mt:if>

解説

  1. まず、setvarblockにentrybodyの値を覚えさせます。 3ten_flagが今回のsetvarblockの名前ですね。<$mt:entrybody strip_linefeeds="1" remove_html="1" count_characters="1"$>

    □次のグローバル・モディファイアを利用します。 strip_linefeeds="1" 公式リファレンス remove_html="1" 公式リファレンス count_characters="1" 公式リファレンス

    strip_linefeedsは改行コードを除去します。 remove_htmlはhtmlタグを除去します。 count_charactersは文字数をカウントします。

    これでentrybodyの値をsetvarblockに代入できました。

  2. そしてif文。 gt="200" これで200文字より多いならば次の処理をしなさい。という命令文が作れます。 あとは...を付けたいentrybodyに対してtrim_to="200"で文字数調整をして、elseで...なしの処理を行うだけ!