Skip to content

Instantly share code, notes, and snippets.

View melat0nin's full-sized avatar
✍️

melat0nin

✍️
  • Edinburgh, Scotland
View GitHub Profile
@melat0nin
melat0nin / gist:1751696
Created February 6, 2012 11:46
c5: Hardcode autonav
$bt = BlockType::getByHandle('autonav');
$bt->controller->displayPagesCID = $currentPage->getCollectionID();
$bt->controller->displayPages = 'custom';
$bt->controller->orderBy = 'display_asc';
$bt->controller->displaySubPages = 'all';
$bt->controller->displaySubPageLevels = 'none';
$bt->render('view');
@melat0nin
melat0nin / gist:1751711
Created February 6, 2012 11:49
c5: If in edit mode
global $c;
if ($c->isEditMode()) {
}
@melat0nin
melat0nin / gist:1751714
Created February 6, 2012 11:49
c5: check if user is logged in
$u = new User;
if ( $u->isLoggedIn() ){
...
}
@melat0nin
melat0nin / gist:1751719
Created February 6, 2012 11:50
c5: hardcode stack/block
// Stack
$nav = Stack::getByName('main_nav');
$nav->display();
// Block
$nav = Block::getByName('main_nav');
$nav->display();
@melat0nin
melat0nin / gist:1751722
Created February 6, 2012 11:51
c5: create Area
$a = new Area('Main');
$a->display($c);
@melat0nin
melat0nin / gist:1751723
Created February 6, 2012 11:51
c5: if collection ID == x, do this
$currentPage = Page::getCurrentPage();
if ($currentPage->getCollectionID() == 1) {
...
}
@melat0nin
melat0nin / gist:1751726
Created February 6, 2012 11:51
c5: get current page's type
$c->getCollectionTypeHandle();
@melat0nin
melat0nin / gist:1751730
Created February 6, 2012 11:52
PHP: Truncate text to x chars
function truncate($string,$words) {
$truncated = preg_replace('/((\w+\W*){' . $words . '}(\w+))(.*)/', '${1}', $string);
if ( strlen($string) > strlen($truncated) ) {
$truncated .= '...';
}
return $truncated;
}
@melat0nin
melat0nin / gist:1751731
Created February 6, 2012 11:52
c5: get page's owner
$owner = $c->getVersionObject()->getVersionAuthorUserName();
@melat0nin
melat0nin / gist:1751735
Created February 6, 2012 11:53
c5: use page ID to get link
function getTheURL($url_id) {
$opg = Page::getById($url_id);
$url=Loader::helper('navigation');
$canonical=$url->getCollectionURL($opg);
$canonical=preg_replace("/index.php\?cID=1$/","",$canonical);
echo $canonical;
}
<a href="<?php getTheURL(140); ?>">