Themes and Style Sheets
Get style sheet
$this->getStyleSheet()
Load stylesheet in header
<?php echo $this->getStyleSheet('main.css')?>
Get theme path
$this->getThemePath()
Print out the name of your site
<?php print SITE; ?>
Get the relative directory of your site (useful for linking)
<?php print DIR_REL; ?>
<a href="<?=DIR_REL?>/">Back to Home</a>
Use to load an image from theme image directory
<img src="<?=$this->getThemePath()?>/image/photo.png">
Set theme path
$view->setTheme(PageTheme::getByHandle('Theme_Handle')
Use a theme path in a block
<?php
$v = View::getInstance();
$themePath = $v->getThemePath();
?>
To display an image from your theme's image directory
<img src="<?php echo $themePath ?>/images/photo.png">
Working with Pages in your Blocks and Themes
Obtain the current Page object
$page = Page::getCurrentPage();
Get a Page's Name
<?php echo $page->getCollectionName() ?>
Get a Page's Handle
<?php print $page->getCollectionHandle(); ?>
Create a div for adding styles to individual pages
<div id="<?php $page->getCollectionHandle() ?> "> </div>
Get a Page's ID
getCollectionID() ?>
Get a Page's Description
getCollectionDescription(); ?>
Display page description
getCollectionDescription() ?>
Get a page's parent page ID
$page ->getCollectionParentID()
Display parent page page ID
<?php echo $page->getCollectionParentID() ?>
Display a Page's Parents Page Name
<?php
$parentPage = Page::getByID($page->getCollectionParentID());
echo $parentPage->getCollectionName();
?>
Find handle of parent page and do something
<?php
$parentPage = Page::getByID($page->getCollectionParentID());
if ( $parentPage->getCollectionName() == 'es' ) {
echo '<h2><a href="/index.php/gallery">Galeria</a>';
} else {
echo '<h2><a href="/index.php/gallery">Gallery</a>';
}
?>
Get a page attribute value
$page->getCollectionAttributeValue()
Display a page text attribute
getAttribute('attribute_handle') ?>
Display an image from page attribute
<img src="<?php echo($page->getAttribute('page_thumbnail')->getVersion()->getRelativePath());?>" width="120px" height="160px">
If a page file/image attribute is set, display download link
<?php
if($page->getAttribute('attribute_name')) {
echo '<a href="' . $page->getAttribute('attribute_name')->getVersion()->getRelativePath() .' ">Download PDF</a>';
}
?>
Get date The page was added/created
<?
print $page->getCollectionDateAdded('F j, Y');
?>
Display date page was added.
getCollectionDateAdded('F j, Y') ?>
Get Public Date/Time in Page Properties
<? $page->getCollectionDatePublic('F j, Y'); ?>
Display Public Date
getCollectionDatePublic('F j, Y') ?>
Display date/time page was last edited
<?php
Loader::model('page_statistics');
echo date('F j, Y', strtotime(pageStatistics::getSiteLastEdit()));
?>
Compare today's date with a page's date/time attribute (end_date) and do something - Using Date Helper to format ($mask=) display of date and time.
<?php
$date = Loader::helper("date");
if($date->getSystemDateTime($page->getCollectionAttributeValue('end_date'), $mask = 'd-m-Y G:i') > $date->getLocalDateTime('now',$mask = 'd-m-Y G:i')) {
echo 'End date is greater than today';
}
?>
Select nav based on page attributes - See language Switching
<?php
if ($page->getCollectionAttributeValue('spanish_menus')) {
$block = Block::getByName('Spanish Menus');
if( is_object($block) ) $block->display();
} else {
$block = Block::getByName('English Menus');
if( is_object($block) ) $block->display();
}
?>
Working with Blocks
Insert a block in a page (from scrapbook)
<?php
$block = Block::getByName('Language Select');
if( is_object($block) ) $block->display();
?>
Add space between blocks in edit mode
<?php if ($page->isEditMode()) { ?>
<div style="min-height: 20px"> </div>
<?php } ?>
Users
Display a User's name
<?php
$u = new User();
echo $u->getUserName();
?>
If a user is logged in do something
<?php
$u = new User();
if($u->isRegistered()); {
echo 'Hello '.$u->getUserName();
}
?>
Credits
This has been collected from our forums and the following articles written by members of our community:
Hello all
NEW THREAD: http://www.concrete5.org/community/forums/documentation_efforts/release-beginnerand039s-guide-to-editing-v1-0/
(go there instead!)
I'm in the process of writing a beginner's guide that will help our clients use the WYSIW…
Started by
melat0nin on
12/06/10 at
1:55 PM
23
replies
I see $c is a global object in all templates that shows the current page collection.
Sometimes for some css juggling it comes very handy to have the page type available as a body css class. Here's the code I deciphered from the Page class/model:
[co…
Started by
pengekcs on
04/07/11 at
12:12 PM
1
reply
Shouldn't you use [code]$u->checkLogin()[/code] under "If a user is logged in do something" instead of [code]$u->isRegistered()[/code] as per
http://www.concrete5.org/community/forums/customizing_c5/isloggedin-and-isregistered/
http://www.concrete5.org/…