6.5 繰り返し処理で区切り文字をつける ★

P.419

ブロックタグのglueモディファイアを利用する

サブテンプレートイメージ

<テンプレートタグ glue=",">
  繰り返す内容
</テンプレートタグ>
<mt:setVar name="foo" value="1","2","3" />
<mt:getVar name="foo" glue="," />

●ブログ記事ページのmeta要素にカテゴリを表示する

「ヘッダー」テンプレートモジュール(サンプルテンプレート)

    ...前略...
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=<mt:publishCharset />" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="<mt:productName version="1" />" />
  <mt:if name="entry_template">
  <meta name="keywords" content="<mt:entryCategories glue=","><mt:categoryLabel></mt:entryCategories>" />
  </mt:if>
  <title><mt:getVar name="title"></title>
    ...後略...

★「ブログ記事」アーカイブテンプレート(デフォルトテンプレート)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
<head>
    <$mt:Include module="HTMLヘッダー"$>
    <mt:if name="entry_template">
      <meta name="keywords" content="<mt:entryCategories glue=","><mt:categoryLabel></mt:entryCategories>" />
    </mt:if>
    <mt:EntryPrevious><link rel="prev bookmark" href="<$mt:EntryPermalink$>" title="<$mt:EntryTitle encode_html="1"$>" /></mt:EntryPrevious>
    <mt:EntryNext><link rel="next bookmark" href="<$mt:EntryPermalink$>" title="<$mt:EntryTitle encode_html="1"$>" /></mt:EntryNext>
    <$mt:EntryTrackbackData$>
    <title><$mt:EntryTitle encode_html="1"$> - <$mt:BlogName encode_html="1"$></title>
</head>
...後略...

006~008を追加します。

ブロックタグにglueモディファイアがない場合

P.420

●特殊変数を利用する

サブテンプレートイメージ(注:glue モディファイアは不要です)

<テンプレートタグ>
  繰り返す内容
  <mt:unless name="__last__">,</mt:unless>
</テンプレートタグ>

サンプル

<mt:archiveList archive_type="Monthly">
  <a href="<mt:archiveLink />"><mt:archiveTitle /></a>
  <mt:unless name="__last__">, </mt:unless>
</mt:archiveList>

●配列変数とgetVarタグのglueモディファイアを利用する

サブテンプレートイメージ(注:setVarBlockタグの終了タグにはスラッシュがつきます)

<テンプレートタグ>
  <mt:setVarBlock name="push(data)">
  繰り返す内容
  <mt:/setVarBlock>
</テンプレートタグ>
<mt:getVar name="data" glue=",">

P.421

サンプル

<mt:setVar name="undef(data)">
<mt:parentCategories>
  <mt:setVarBlock name="push(data)">
  <a href="<mt:categoryArchiveLink />"><mt:categoryLabel /></a>
  </mt:setVarBlock>
</mt:parentCategories>
<mt:getVar name="data" glue=",">

サンプル

    ...前略...
  <mt:setVarBlock name="push(data)"><a href="<mt:categoryArchiveLink />"><mt:categoryLabel /></a></mt:setVarBlock>
    ...後略...

ウェブページ

Powered by Movable Type 4.261

このアーカイブについて

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。