LoginSignup
6
6

More than 5 years have passed since last update.

baserCMSのヘッド要素テンプレ

Last updated at Posted at 2013-08-26

コーポレートにちょうどいい国産CMS baserCMS を使って制作をしているので、制作上のメモを書きます。

Doc宣言+Meta テンプレ

XHTML1.0

/app/webroot/themed/***/layouts/default.php
<?php $bcBaser->xmlHeader() /* IE6の互換モード問題が危惧される場合は呼び出さないほうがいい */ ?>
<?php $bcBaser->docType() ?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
<?php $bcBaser->charset() ?>
<?php $bcBaser->title() ?>
<?php $bcBaser->metaDescription() ?>
<?php $bcBaser->metaKeywords() ?>
</head>

出力↓

output
<?xml version="1.0" encoding="UTF-8" ?>
<!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" lang="ja" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>...</title>
<meta name="description" content="..." />
<meta name="keywords" content="..." />
</head>

HTML5

/app/webroot/themed/***/layouts/default.php
<?php $bcBaser->docType('html5') ?>
<html lang="ja">
<head>
<meta charset="<?php echo ($charset = strtolower(Configure::read('App.encoding'))) ? $charset : 'utf-8' ?>">
<?php $bcBaser->title() ?>
<meta name="description" content="<?php echo $bcBaser->getDescription() ?>">
<meta name="keywords" content="<?php echo $bcBaser->getKeywords() ?>">
</head>

出力↓

output
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>...</title>
<meta name="description" content="...">
<meta name="keywords" content="...">
</head>

XHTML1.0への対応は基本的に綺麗にできます。htmlタグの出力が動的でない理由はidやclassの付加などの対応に柔軟になっていると解釈しました。

HTML5は、これはもう基本的に対応していないものを強引に出力してみた、といった感じです。文字コードの標準の取得メソッドがないのがちょっと残念。

$bcBaser->docType()だけ微妙に対応しているところもなんか悲しく、しかも< !DOCTYPE html>後方互換のためのドキュメント宣言 であり、今後HTML5.1やHTML6となっても(後方互換のために)この宣言をする必要がある(つまりHTML5限定の宣言なわけではない)から$bcBaser->docType('html5')というように'html5'という引数だけでしかこの宣言が出力できないのは間違っていると思います。理想としては引数が空なら< !DOCTYPE html>を出力する仕様がいいのかな。

descriptionとkeywordは単純に 空要素の閉じスラッシュを無くしたいだけ です。HTML5の仕様上あっても問題ないけど、『 どっちかに統一 』できれば理想的。HTMLエディタがHTML5の場合、あんまり閉じスラッシュに対応していないことが多いの(と、個人的な好み)でここでは「閉じスラなし」の場合を再現してみました。

ちなみにこれはbaserCMSの機能というより、CakePHPの標準のヘルパーがこうなっているみたいです。baserCMSがこのあたりを上手くオーバーライドして抽象化できれば助かるんだけどなぁと思います。(でもCakeのコード読んだら一筋縄ではいかなそう。根本的にコード書き変える必要があるかもしれません。)

そもそもの話

Doc宣言や文字コードは動的に書く必要あるのか? と思いました。

CakePHPにヘルパーが存在するので採用いるのかはわからないのですが、今の段階で必要性はまだ見えません。descriptionとkeywordは動的に管理したいので必要だけど、Doc宣言と文字コードの変更が必要な場合って、結局テンプレのHTMLも大きく変更しないければいけないことがほとんどのはずです。必要なケースを知っている方は教えて下さい。。。

それを踏まえてHTML5のテンプレ

/app/webroot/themed/***/layouts/default.php
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<?php $bcBaser->title() ?>
<meta name="description" content="<?php echo $bcBaser->getDescription() ?>">
<meta name="keywords" content="<?php echo $bcBaser->getKeywords() ?>">
</head>

たぶんこれがスマートなはず。

他にもあるメタ系出力タグ

iconcssjsなど他にも出力メソッドが用意されています。使い方がわかったら適宜この記事に追加していこうかと思います(cssjsは機能的に奥が深そうだら別記事にするかも)。

公式のリファレンス

BaserHelper 出力系命令 | baserCMS 2系関数リファレンス

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6