2008年11月12日
コメント投稿者の表示を valid にする
Posted at November 12,2008 1:55 AM
Category:[コメント, テンプレートタグ]
Tag:[Comment, Customize, MovableType, Validation]
Category:[コメント, テンプレートタグ]
Tag:[Comment, Customize, MovableType, Validation]
コメント投稿者の表示には MTCommentAuthorLink タグを使用していますが、コメント投稿者名に「&」などの実体参照が必要な文字が含まれている場合、そのページが valid でなくなります。
グローバルモディファイアとして、escape モディファイアや encode_html モディファイアが用意されていますが、MTCommentAuthorLink タグにこのモディファイアを適用すると、タグで出力されるリンク(のアングルブラケット)まで実体参照されてしまいます。
1.通常のコメント投稿者表示で MTCommentAuthorLink タグを使用
下は通常のコメント投稿者表示で MTCommentAuthorLink タグを使用した場合の、サブテンプレートとその出力(ソースコード)です。
Posted by <mt:commentAuthorLink default_name="Anonymous" show_email="0" />
出力
Posted by <a title="http://www.koikikukan.com/" href="http://www.koikikukan.com/" rel="nofollow">yujiro</a>
2.MTCommentAuthorLink タグに escape モディファイアを適用した失敗例
下は、MTCommentAuthorLink タグに escape モディファイアを適用したときの、サブテンプレートとその出力(ソースコード)です。出力で、本来アングルブラケットになるべき (X)HTML 要素のタグが実体参照されてしまっています。
Posted by <mt:commentAuthorLink default_name="Anonymous" show_email="0" escape="html" />
出力
Posted by <a title="http://www.koikikukan.com/" href="http://www.koikikukan.com/">yujiro</a>
ここでは、他のテンプレートタグを組み合わせて、コメント投稿者を実体参照するカスタマイズを紹介します。
3.配布テンプレートの修正例
ブログ管理画面より「デザイン」→「テンプレート」で「コメント詳細」テンプレートモジュール編集画面を開き、赤色の MTCommentAuthorLink タグの部分を、青色の内容に変更してください。
変更前
<div class="comment"<mt:ifArchiveTypeEnabled archive_type="Individual"> id="c<mt:commentID />"</mt:ifArchiveTypeEnabled>>
<div class="comment-content">
<mt:ifCommentParent>
<p><a href="<mt:commentParent>#comment-<mt:commentID /></mt:commentParent>"><mt:commentParent>No.<mt:commentID />の<mt:commentAuthor /></mt:commentParent></a>さんのコメントへの返信</p>
</mt:ifCommentParent>
<mt:commentBody /></div>
<p class="comment-footer">
Posted by <mt:commentAuthorLink default_name="Anonymous" show_email="0" /> <mt:if tag="CommentAuthorIdentity"><mt:commentAuthorIdentity /></mt:if> at <mt:commentDate /><mt:ifCommentsAccepted> | <mt:commentReplyToLink /></mt:ifCommentsAccepted>
</p>
</div>
変更後
<div class="comment"<mt:ifArchiveTypeEnabled archive_type="Individual"> id="c<mt:commentID />"</mt:ifArchiveTypeEnabled>>
<div class="comment-content">
<mt:ifCommentParent>
<p><a href="<mt:commentParent>#comment-<mt:commentID /></mt:commentParent>"><mt:commentParent>No.<mt:commentID />の<mt:commentAuthor escape="html" /></mt:commentParent></a>さんのコメントへの返信</p>
</mt:ifCommentParent>
<mt:commentBody /></div>
<p class="comment-footer">
Posted by <mt:if tag="commentURL"><a href="<mt:commentURL />"></mt:if><mt:commentAuthor default="Anonymous" escape="html" /><mt:if tag="commentURL"></a></mt:if> <mt:if tag="CommentAuthorIdentity"><mt:commentAuthorIdentity /></mt:if> at <mt:commentDate /><mt:ifCommentsAccepted> | <mt:commentReplyToLink /></mt:ifCommentsAccepted>
</p>
</div>
4.デフォルトテンプレート(抜粋)の修正例
ブログ管理画面より「デザイン」→「テンプレート」で「コメント」テンプレートモジュール編集画面を開き、赤色の MTCommentAuthorLink タグの部分を、青色の内容に変更してください。
変更前
...前略...
<div class="asset-meta">
<span class="byline">
<$mt:CommentAuthorIdentity$>
<mt:IfCommentParent>
<span class="vcard author"><$mt:CommentAuthorLink$></span>から<a href="<mt:CommentParent><$mt:CommentLink$></mt:CommentParent>"><mt:CommentParent><$mt:CommentAuthor$></mt:CommentParent></a>への返信
<mt:Else>
<span class="vcard author"><$mt:CommentAuthorLink$></span>
</mt:IfCommentParent>
| <a href="<$mt:CommentLink$>"><abbr class="published" title="<$mt:CommentDate format_name="iso8601"$>"><$mt:CommentDate$></abbr></a>
<mt:IfCommentsAccepted>
| <$mt:CommentReplyToLink$>
</mt:IfCommentsAccepted>
</span>
</div>
...後略...
変更後
...前略...
<div class="asset-meta">
<span class="byline">
<$mt:CommentAuthorIdentity$>
<mt:IfCommentParent>
<span class="vcard author"><mt:if tag="commentURL"><a href="<mt:commentURL />"></mt:if><mt:commentAuthor default="Anonymous" escape="html" /><mt:if tag="commentURL"></a></mt:if></span>から<a href="<mt:CommentParent><$mt:CommentLink$></mt:CommentParent>"><mt:CommentParent><$mt:CommentAuthor$></mt:CommentParent></a>への返信
<mt:Else>
<span class="vcard author"><mt:if tag="commentURL"><a href="<mt:commentURL />"></mt:if><mt:commentAuthor default="Anonymous" escape="html" /><mt:if tag="commentURL"></a></mt:if></span>
</mt:IfCommentParent>
| <a href="<$mt:CommentLink$>"><abbr class="published" title="<$mt:CommentDate format_name="iso8601"$>"><$mt:CommentDate$></abbr></a>
<mt:IfCommentsAccepted>
| <$mt:CommentReplyToLink$>
</mt:IfCommentsAccepted>
</span>
</div>
...後略...
Posted by yujiro このページの先頭に戻る
- Movable TypeでreCaptchaを利用する
- Movable Typeでカテゴリ別+ブログ記事別に新着コメントを表示する
- Movable Type 5でコメント投稿フォームをポップアップする
- Movable TypeのコメントでFacebookアカウント認証を有効にする
- Yahoo! JAPAN OpenID を省略表示する(その2)
- コメントにHTMLタグ挿入ボタンをつける(MT4/MT5版)
- コメント投稿にTwitterのOAuth認証を導入
- Movable Type 5でのMTCommentsタグの動作
- ブログ記事とコメントをひとつのフィードで配信する
- コメント一覧からウェブページのコメントを除外して表示する
- Movable Typeのコメントにimg要素を許容する
- Movable Type(MT)のコメント投稿者の承認と禁止について
- Movable Type 5(MT5)のコメントのページ分割機能(その2:カスタマイズ)
- Movable Type 5 のコメントのページ分割機能(その1:概要)
- Movable Type の Captcha の表示を変更する
- ブログ記事ページのサイドバーにブログ記事のコメント一覧を表示する
- コメント出力数に応じてコメント番号を制御する
- コメント番号を降順で表示する
- Movable Type のコメント投稿で「コメントを投稿できませんでした。エラー: 短い期間にコメントを大量に送りすぎです。しばらくたってからやり直してください。」というエラー処理について
- MovableType 4.25 のコメント投稿でJavaScript イベント属性(onclick等)を有効にする
この記事を読んだ人はこんな記事も読んでいます
- Web Designing (ウェブデザイニング) 2009年 01月号
- Movable Type 4.23 リリース
- コメント投稿者欄が無記名の時に代替名を表示する
- コメント投稿者の情報表示をカスタマイズする
- Movable Type のブロックタグにファンクションタグで使うモディファイアを指定する
- ポップアップ画面を用いたコメント投稿(その3:公開テンプレート修正方法)
- コメント投稿時のPerlエラーを解消する
- Movable Type でブログを複数作成する
- 破損した Word 文書を修復する方法
- エントリー投稿時のフォームボタンをグレーアウトするプラグイン for Movable Type 3.3x
人気エントリー
Hatena Hot Entries
Hatena Entries
トラックバックURL
コメント
コメントする
greeting
