コミュニティブログや掲示板で、記事やコメントの投稿に、カスタムフィールドを利用するときがあります。カスタムフィールドを利用するためには、テンプレートに必要な内容を記述しますが、その際の注意点を紹介します。
テンプレートタグリファレンス MTCommentCustomFields (日本語, English) では、以下のように記述されています。
<input type="hidden" name="blog_id" value="<MTBlogID>" />
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
<mt:CommentCustomFields>
<mt:SetVarBlock name="custom_field_name"><$mt:CustomFieldName$></mt:SetVarBlock>
<mt:SetVarBlock name="field-content"><$mt:CustomFieldHTML$></mt:SetVarBlock>
<mt:SetVarBlock name="custom_field_id">profile_<$mt:CustomFieldName dirify="1"$></mt:SetVarBlock>
<$mt:Include module="Form Field" id="$custom_field_id" class="" label="$custom_field_name"$>
</mt:CommentCustomFields>
customfield_beacon は、フォーム内にカスタムフィールドがあることを伝えるキーワードです。それはさておき、注意しなければいけない点は、変数 custom_field_id の扱いです。
MTCustomFieldName に対して dirify をかけているために、フィールド名が日本語だけの場合に _ のみになってしまいます。custom_field_id は input 要素 (テキストの場合) の id 属性に入るため一意でなければいけません。
解決方法は、MTCustomFieldName ではなく MTCustomFieldBaseName を使うことになります。タグリファレンスの例は、英語環境であれば問題はありませんが、日本語環境では残念なことになるので、ご注意ください。
Recent Comments