【baserCMS:初心者向け】ページごとにヘッダーなどの読み込みを分岐させる


読み込みの分岐

例えばページによってヘッダーやフッターを切り分けたい時があると思います。
下層ページはヘッダーのデザインが違うとかメイン画像サイズが変わるとかメニューが変わるとか
そういう時に使えるタグです。
「"About"というスラッグのページだけはabout_header.phpを読み込む。」
「"Service"というスラッグのページだけはservice_header.phpを読み込む。」
「それ以外のページは共通でheader.phpを読み込む。」
といった感じになります。

<?php if($this->BcBaser->getContentsName() === 'About'): ?>
    <?php $this->BcBaser->element('about_header') ?>
<?php elseif($this->BcBaser->getContentsName() === 'Service'): ?>
    <?php $this->BcBaser->element('service_header') ?>
<?php else: ?>
    <?php $this->BcBaser->element('header') ?>
<?php endif ?>

トップページだけに表示したい時はこんな感じ。

<?php if($this->BcBaser->isHome()): ?>
<!-- トップページのみに出力する内容 -->
<?php endif ?>

ちなみに記事の詳細ページのみ分岐したい時はこうなります。

<?php if ($this->BcBaser->isBlogSingle()): ?>
    <?php $this->BcBaser->element('single_header') ?>
<?php else: ?>
    <?php $this->BcBaser->element('header') ?>
<?php endif; ?>

あと〇〇ページじゃない時!とか

<?php if (strtolower($this->BcBaser->getContentsName(true)) !== 'work'): ?>
<?php endif; ?>

複数ページをまとめて指定だとこんな感じですね。(スラッグがpolicyページかfaqページじゃない時)

<?php
$slug = strtolower($this->BcBaser->getContentsName(true));
if ($slug !== 'policy' && $slug !== 'faq'): ?>
〜コンテンツ〜
<?php endif; ?>