Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active December 21, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/6256582 to your computer and use it in GitHub Desktop.
Save hissy/6256582 to your computer and use it in GitHub Desktop.
concrete5 theme & template customize tips
<?php
$a = new GlobalArea('Mobile Main Nav');
$a->disableControls();
$a->display();
?>
<?php
// $this はBlockViewクラスのオブジェクト。
$obj = $this->getBlockObject();
// $obj はBlockクラスのオブジェクトになる。
// ブロック名を表示(ブロック名はカスタムテンプレートの画面で設定できる)
echo $obj->getBlockName();
if ($obj->getBlockDisplayOrder() == 0) {
// ブロックが先頭に表示されている場合
}
$cParentID = 0;
switch($controller->displayPages) {
case 'current':
$cParentID = $controller->cParentID;
if ($cParentID < 1) {
$cParentID = 1;
}
break;
case 'top':
// top level actually has ID 1 as its parent, since the home page is effectively alone at the top
$cParentID = 1;
break;
case 'above':
$cParentID = $controller->getParentParentID();
break;
case 'below':
$cParentID = $controller->cID;
break;
case 'second_level':
$cParentID = $controller->getParentAtLevel(2);
break;
case 'third_level':
$cParentID = $controller->getParentAtLevel(3);
break;
case 'custom':
$cParentID = $controller->displayPagesCID;
break;
default:
$cParentID = 1;
break;
}
$parent = Page::getByID($cParentID); ?>
<h3><?php echo $parent->getCollectionName(); ?></h3>
<?php $v = View::getInstance(); ?>
<img src="<?php echo $v->getThemePath(); ?>/images/example.png" alt="">
<?php
$cParentID = ((int) $controller->cParentID) ? $controller->cParentID : 1;
$cParent = Page::getByID($cParentID);
?>
<h3><?php echo $cParent->getCollectionName()?></h3>
<?php
$a = new Area('Main');
/**
* $a->setBlockWrapperStart(string $html, boolean $hasReplacements = false);
* 第2引数をtrueにすると下記のトークンをHTMLに埋め込むことができる
* %1$s -> ブロックID
* %2$s -> ブロックタイプハンドル
* %3$s -> ブロック/スタック名
* %4$s -> エリア内のブロック位置(最初のブロックは1、次のブロックは2)
* %5$s -> 'odd' または 'even' (CSSで縞々にするために使える)
*/
$a->setBlockWrapperStart('<div class="bid%1$s bt%2$s bnum%4$s %5$s">',true);
$a->setBlockWrapperEnd('</div>');
$a->display($c);
?>
<?php
$a = new Area('Main');
$a->setBlockLimit(5);
$a->display($c);
?>
<?php
$a = new Area('Main');
if ($a->getTotalBlocksInArea($c) > 0) : ?>
<h1>This is a Main Area.</h1>
<?php
endif;
$a->display($c);
<?php
if($c->isEditMode()) { ?>
編集モードの時だけ表示される何か
<?php } ?>
<?php
$c = Page::getCurrentPage(); // ブロックからはこの行が必要
if($c->isEditMode()) { ?>
編集モードの時だけ表示される何か
<?php } ?>
<?php
$u = new User();
if ($u->isRegistered()) { ?>
ログインしているときだけ表示される何か
<?php } ?>
<?php defined('C5_EXECUTE') or die("Access Denied.");?>
<div class="hide-for-small">
<?php
$c = Page::getCurrentPage();
$cp = new Permissions($c);
if ($cp->canViewPageVersions()) {
$stack = Stack::getByID($stID);
} else {
$stack = Stack::getByID($stID, 'ACTIVE');
}
if (is_object($stack)) {
$ax = Area::get($stack, STACKS_AREA_NAME);
$axp = new Permissions($ax);
if ($axp->canRead()) {
$ax->display($stack);
}
}
?>
</div>
@rajeshkhatri13
Copy link

Hi Hissy,

Nice information you had posted, can you please help me for setblockwrapperstart issue i am facing with 5.7 version.

I have use below code...

<?php      
    $a = new Area('Main');
    $a->setBlockWrapperStart('<div id="article%4$s">', true);
    $a->setBlockWrapperEnd('</div>');
    $a->display($c);
?>

but it prints article%4$s instead of article1,article2...
Any help will be appreciated.
Regards,
Raj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment