Table of Contents

Themes and Style Sheets

Get Style Sheet

$this->getStyleSheet();
 
Load stylesheet in header
 
<?php echo $this->getStyleSheet('main.css')?>

Get Theme Path

$this->getThemePath();
 
Use to load an image from theme image directory
 
<img src="<?=$this->getThemePath()?>/images/photo.png">
 
OR
 
<?php
  $v = View::getInstance();
  $v->getThemePath();
?>

Set Theme Path

Use a Theme Path In a Block
 
<?php
  $v = View::getInstance();
  $themePath = $v->getThemePath();
?>
 
  To display an image from your themes image directory
 
  <img src="<?php echo $themePath ?>/images/photo.png">

Working With Blocks

Add a Block Area

<?php 
    $a = new Area('AREA_NAME');
    $a->display($c);
?>

Wrap Each Block In An Area With Divs

<?php 
  $a = new Area('sidebar');
  $a->setBlockWrapperStart('<div class="box">');
  $a->setBlockWrapperEnd('</div>');
  $a->display($c); 
?>

Add Space Between Blocks In Edit Mode

<?php 
  if ($c->isEditMode()) { ?>
    <div style="min-height: 20px;"> </div>
  <?php } ?>

Add a Global Area for a Stack In a Page

<?php
  $a = new GlobalArea('STACK_NAME');
  $a->display();
?>

Add a Stack In a Page

<?php
$stack = Stack::getByName('STACK_NAME');
$stack->display();
?>

Get Stack Names (or Handles)

<?php
  Loader::model('stack/list');
  $stm = new StackList();
  $stm->filterByGlobalAreas(); 
  // Use filterByGlobalAreas() or filterByUserAdded()
  $stacks = $stm->get();
 
  foreach($stacks as $st) {
    print  $st->getCollectionName();
    //  Use $st->getCollectionName(),  $st->getCollectionHandle(), etc.
  }
?>

<?php
  $stm = new StackList();
  $stm->filterByGlobalAreas(); 
  // Use filterByGlobalAreas() or filterByUserAdded()
  $stacks = $stm->get();
 
  foreach($stacks as $st) {
    print  $st->getCollectionName();
    //  Use $st->getCollectionName(),  $st->getCollectionHandle(), etc.
  }
?>

Get URL for Block Directory

<img src="<?php echo $this->getBlockURL() ?>/images/image.png">

Working with Pages in Blocks and Themes

Add a Page Type

<?php
  /* Check if page exists. */
 
  Loader::model('collection_types');
  $pageType = CollectionType::getByHandle('[page_type_handle]');
 
  /* Addd new page if does not exist. */
 
  if(!is_object($pageType)) {
    $data['ctHandle'] = '[page_type_handle]';
    $data['ctName'] = t('[page_type_name]');
    $newPage = CollectionType::add($data, $pkg);
  }
?>

Display a Page's Parent Page Name

<?php
  $page=Page::getByID($c->getCollectionParentID());
  echo $page->getCollectionName();
?>

Display Top Level Parent Name

<?php 
  global $c;
  $nh = Loader::helper('navigation');
  $cobj = $nh->getTrailToCollection($c);
 
  $rcobj = array_reverse($cobj);
    if(is_object($rcobj[1])) {
      $pID  = $rcobj[1]->getCollectionID();
      $page = Page::getByID($pID);  
      echo $page->getCollectionName();
    }else{
      echo $c->getCollectionName();
    }  
?>

<?php 
  $c = Page::getCurrentPage();
  $nh = Core::make('helper/navigation');
  $cobj = $nh->getTrailToCollection($c);
 
  $rcobj = array_reverse($cobj);
    if(is_object($rcobj[1])) {
      $pID  = $rcobj[1]->getCollectionID();
      $page = Page::getByID($pID);  
      echo $page->getCollectionName();
    }else{
      echo $c->getCollectionName();
    }  
?>

Get Current Page Object

global $c;

$page = Page::getCurrentPage();

Get Date The Page Was Added/Created

<?php
$c->getCollectionDateAdded('F j, Y')
?>
 
Display date page was added.
 
<?php echo $c->getCollectionDateAdded('F j, Y') ?>

Get Handle of Parent Page and Do Something

<?php
  $page=Page::getByID($c->getCollectionParentID());
 
  if ( $page->getCollectionName() == 'es' ) {
    echo '<a href="/index.php/gallery">Galería</a>';
  } else {
    echo '<a href="/index.php/gallery">Gallery</a>';
  }
?>

Get a Page's Description

$c->getCollectionDescription();
 
Display page description
 
<?php echo $c->getCollectionDescription() ?>

Get a Page's Handle

$c->getCollectionHandle();
 
Create a div for adding styles to individual pages
 
<div id="<?php echo $c->getCollectionHandle() ?> "> </div>
 
Add a class to a div based on page handle
 
<div id="header" class="<?php echo $c->getCollectionHandle() ?>"> </div>

Get a Page's ID

$c->getCollectionID();
 
Display page ID
 
<?php echo $c->getCollectionID() ?>

Get a Page's Name

$c->getCollectionName();
 
Display page name
 
<?php echo $c->getCollectionName() ?>

Get a Page's Parent Page ID

$c->getCollectionParentID();
 
Display parent page page ID
 
<?php echo $c->getCollectionParentID() ?>

Get a Pages Owner ID

$pageOwner = $c->getCollectionUserID()

Get Current Page URL

<?php
$nh = Loader::helper('navigation');
$URL = $nh->getCollectionURL($c);
?>

<?php
$nh = Core::make('helper/navigation');
$URL = $nh->getCollectionURL($c);
?>

Get a Page Type's Name

$c->getCollectionTypeName();
 
Set a class to a page types name.
 
<?php 
  if($c->getCollectionTypeName() == 'Full Width'){ 
    echo 'class="full-width"';
  }
?>

Get Site Name

<?php
echo SITE;
?>

<?php
echo Config::get('concrete.site');
?>

Get Public Date/Time In Page Properties

$c->getCollectionDatePublic('F j, Y')
 
Display Public Date
 
<?php echo $c->getCollectionDatePublic('F j, Y') ?>

<?php
$dateHelper = Core::make('helper/date');
 
echo $dateHelper->getSystemDateTime($c->getCollectionDatePublic(), $mask = 'l, F d, Y  g:ia')
?>

Get Date Last Edited

<?php
// Load Date Helper
$date = Loader::helper("date");
 
// Get Blocks in Main area
foreach($c->getBlocks('Main') as $b) {
   $bDate[$i] = $b->getBlockDateLastModified();
   $i ++;
}
 
// Reverse Sort Date Array
rsort( $bDate );
 
//Echo Date and Time Page last Edited
echo $date->getLocalDateTime($bDate[0],$mask = 'm-d-Y g:i:s');
?>

<?php
// Load Date Helper
$date = Core::make('helper/date'); 
 
// Get Blocks in Main area
foreach($c->getBlocks('Main') as $b) {
   $bDate[$i] = $b->getBlockDateLastModified();
   $i ++;
}
 
// Reverse Sort Date Array
rsort( $bDate );
 
//Echo Date and Time Page last Edited
echo $date->getLocalDateTime($bDate[0],$mask = 'm-d-Y g:i:s');
?>

Embed Autonav in a Theme Page

<?php 	
  $bt = BlockType::getByHandle('autonav');
  $bt->controller->displayPages = 'top'; // 'top', 'above', 'below', 'second_level', 'third_level', 'custom', 'current'
  $bt->controller->displayPagesCID = ''; // if display pages is set ‘custom’
  $bt->controller->orderBy = 'display_asc';  // 'chrono_desc', 'chrono_asc', 'alpha_asc', 'alpha_desc', 'display_desc','display_asc'             
  $bt->controller->displaySubPages = 'all';  //none', 'all, 'relevant_breadcrumb', 'relevant'          
  $bt->controller->displaySubPageLevels = 'all'; // 'enough', 'enough_plus1', 'all', 'custom'
  $bt->controller->displaySubPageLevelsNum = ''; // if displaySubPages is set 'custom'
  $bt->render('view'); // for template 'templates/template_name';
?>

Working With Page Attributes

Add a Page Attribute Programmatically

<?php
Loader::model('collection_types');
Loader::model('collection_attributes');
 
// add checkbox attribute
$att = AttributeType::getByHandle('boolean');
$testAttribute3=CollectionAttributeKey::getByHandle('attribute_handle');
if( !is_object($testAttribute3) ) {
    CollectionAttributeKey::add($att, array('akHandle' => 'attribute_handle', 'akName' => t('Attribute Name'), 'akIsSearchable' => true, 'akCheckedByDefault' => true), $pkg);
}
?>

<?php
namespace
use \Concrete\Core\Attribute\Type as AttributeType;
use CollectionAttributeKey;
 
// add checkbox attribute
$att = AttributeType::getByHandle('boolean');
$testAttribute3=CollectionAttributeKey::getByHandle('attribute_handle');
if( !is_object($testAttribute3) ) {
    CollectionAttributeKey::add($att, array('akHandle' => 'attribute_handle', 'akName' => t('Attribute Name'), 'akIsSearchable' => true, 'akCheckedByDefault' => true), $pkg);
}
?>

Test That a Value Is Set in an Attribute

<?php
  if ($c->getCollectionAttributeValue(attribute_hande)) {
  Do Something Here;
  }
?>

Get a Page Attribute Value

$c->getCollectionAttributeValue()
 
Display a page text attribute
 
<?php echo $c->getCollectionAttributeValue('attribute_hande') ?>
 
*In some blocks you may need to substitute with $cobj

Get an Attribute Key by Handle

Loader::model('attribute/categories/collection');		
$atKey = CollectionAttributeKey::getByHandle('handle');

$atKey = CollectionAttributeKey::getByHandle('handle');

Display An Image From Page Attribute

<img src="<?php echo ($c->getAttribute('attribute_handle')->getVersion()->getRelativePath());?>" width="120px" height="160px">

<?php
  if($c->getAttribute('attribute_name')) {
    echo '<a href="' . $c->getAttribute('attribute_handle')->getVersion()->getRelativePath() .' ">Download PDF</a>';
  }
?>

Get a File/Image Atributes File Name

<?php
$c->getAttribute('attribute_handle')->getFileName() 
?>

Get All Page Attributes

<?php
Loader::model('attribute/key');
$atKeys = AttributeKey::getList('collection');
 
foreach($atKeys as $ak) {
  echo  $ak->akName . '<br/>';
}
?>

(in view.php)
<?php
$atKeys = CollectionAttributeKey::getList();
 
foreach($atKeys as $ak) {
  echo  $ak->akName . '<br/>';
}
?>
 
(in controller.php)
 
<?php
namespace
use View;
 
$atKeys = CollectionAttributeKey::getList();
 
foreach($atKeys as $ak) {
  pageAttributes[] =  $ak->akName;
}

(in view.php)
<?php
$atKeys = CollectionAttributeKey::getList();
 
foreach($atKeys as $ak) {
  echo  $ak->getAttributeKeyName() . '<br/>';
}
?>
 
(in controller.php)
 
<?php
namespace
use View;
 
$atKeys = CollectionAttributeKey::getList();
 
foreach($atKeys as $ak) {
  pageAttributes[] =  $ak->getAttributeKeyName();
}

Get all Attributes in a Set

<?php
Loader::model('attribute/key');
Loader::model('attribute/set');
 
$atSet = AttributeSet::getByHandle('attribute_set_handle');
$atKeys = $atSet->getAttributeKeys();
 
foreach($atKeys as $ak) {
  echo $ak->akName;
}

(in view.php)
$atSet = AttributeSet::getByHandle('attribute_set_handle');
$atKeys = $atSet->getAttributeKeys();
 
foreach($atKeys as $ak) {
  echo $ak->akName;
}
 
(in controller.php)
 
namespace
use \Concrete\Core\Attribute\Set as AttributeSet;
 
$atSet = AttributeSet::getByHandle('attribute_set_handle');
$atKeys = $atSet->getAttributeKeys();
 
foreach($atKeys as $ak) {
  $setNmes[] = $ak->akName;
}

(in view.php)
$atSet = AttributeSet::getByHandle('attribute_set_handle');
$atKeys = $atSet->getAttributeKeys();
 
foreach($atKeys as $ak) {
  echo $ak->getAttributeKeyName();
}
 
(in controller.php)
 
namespace
use \Concrete\Core\Attribute\Set as AttributeSet;
 
$atSet = AttributeSet::getByHandle('attribute_set_handle');
$atKeys = $atSet->getAttributeKeys();
 
foreach($atKeys as $ak) {
  $setNmes[] = $ak->getAttributeKeyName();
}

Display/Get Options From a Select Attribute

<?php 
  Loader::model('attribute/type');
  Loader::model('attribute/categories/collection');
 
  $ak = CollectionAttributeKey::getByHandle('attribute_handle');
  $sa = new SelectAttributeTypeController(AttributeType::getByHandle('select'));
  $sa->setAttributeKey($ak);
  $values = $sa->getOptions();
 
  foreach ($values as $v) {
    echo $v->value;
  }	
?>				

Display/Get Options From a Select Attribute

<?php 
  use CollectionAttributeKey;
 
  $ak = CollectionAttributeKey::getByHandle('attribute_handle');
  if ( is_object($ak)) {
    $type = $ak->getAttributeType();
    $controller = $type->getController();
    $controller->setAttributeKey($ak);
    $options = $controller->getOptions();
 
    foreach($options as $option){
      print $option . '<br/>';
    }
  }
 ?>				

Display/Get multiple Values From a Select Page Attribute

<?php
Loader::model("attribute/categories/collection");
 
  $selectedOptions = $c->getCollectionAttributeValue('attribute_handle');
  if (is_object($selectedOptions)) {
    foreach ($selectedOptions as $opt) {
	echo $opt;
    }
  }
?>				

Add select attribute with attribute set

<?php 
  // add select with attribute set page attributes 
 
  // Set attribute category	
  $akCat = AttributeKeyCategory::getByHandle('collection');
  $akCat->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
  $akCatSet = $akCat->addSet('attribute_set_handle', t('Attribute Set Name'),$pkg);
 
  $atType = AttributeType::getByHandle('select');
 
  // test for existing attribute
  $myAttribute = CollectionAttributeKey::getByHandle('attribute_handle'); 
 
  // Add attribute
  if( !is_object($myAttribute) ) {
 
    CollectionAttributeKey::add($atType, 
    array('akHandle' => 'attribute_hande', 
    'akName' => t('Attribute Name'), 
    'akIsSearchable' => true, 
    'akIsSearchableIndexed' => true,
    'akSelectAllowMultipleValues' => false,
    'akSelectAllowOtherValues' => false,
    'akSelectOptionDisplayOrder' => 'alpha_asc',  // alpha_asc or popularity_desc
    ),$pkg)->setAttributeSet($akCatSet); 
 
    //Add option values
    $myAttribute = CollectionAttributeKey::getByHandle('attribute_handle');
    SelectAttributeTypeOption::add( $mMakerAttribute, 'Select Option One');
    SelectAttributeTypeOption::add( $mMakerAttribute, 'Select Option Two');
    SelectAttributeTypeOption::add( $mMakerAttribute, 'Select Option Three');
 }
?>

Select Nav Based On Page Attributes

(See language Switching)
 
<?php
  if ($c->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 Users

Add a User Attribute Programmatically

<?php
  Loader::model('user_attributes');
  //add boolean type user attribute 
  $boolt = AttributeType::getByHandle('boolean');
  $attributeHandle=UserAttributeKey::getByHandle('attribute_handle');
 
  if( !is_object($attributeHandle) )
    UserAttributeKey::add($boolt, array('akHandle' => 'atribute_handle', 'akName' => t('Attribute name'), 'akIsSearchable' => false, 'uakProfileEdit' => false, 'uakRegisterEdit' => false, 'akCheckedByDefault' => false));
}
?>

Delete User Attribute Programmatically

<?php
  Loader::model('user_attributes');
  $attributeHandle = UserAttributeKey::getByHandle('atribute_handle');
   if( is_object($attributeHandle) )
     $attributeHandle->delete();
}
?>

Get a User Attribute for Person Logged In

<?php
  $u = new User();
  if($u->isLoggedIn()) {
    $ui = UserInfo::getByID($u->getUserID());
    echo $ui->getAttribute('attribute_name');	
}
?>

Set a User Attribute for Person Logged In

<?php
  $u = new user();
  $ui = UserInfo::getByID($u->getUserID());
  $ui->setAttribute('attributenName', 'value');
?>

Delete a User Attribute

<?php
  Loader::model('user_attributes');
  $attributeKey = UserAttributeKey::getByHandle('user_attribute_name');
  if( is_object($attributeKey) )
    $attributeKey->delete();
?>

Display/Get Options From a User Select Attribute

<?php
  Loader::model('attribute/type');
  Loader::model('attribute/categories/user');
 
  $ak = UserAttributeKey::getByHandle('project_name');
  $sa = new SelectAttributeTypeController(AttributeType::getByHandle('select'));
  $sa->setAttributeKey($ak);
  $values = $sa->getOptions();
 
  foreach ($values as $v) {
    echo $v->value;
  }
?>

Add a User To a Group

<?php
  $u = new User();
  $u->getByUserID($uID);
  $groupName = Group::getByName('Name_Of_Your_Group');
  $u->enterGroup($groupName);
?>

Get All User Group Names

<?php
Loader::model('search/group');
 
$gl = new GroupSearch();
$gResults = $gl->getPage();
 
foreach ($gResults as $g) {
  echo  $g['gName'];
}
?>	

Display a Users Name

<?php
  $u = new User();
  echo $u->getUserName();
?>

If Logged in Adjust Background Position

<?php 
  $u = new User();
 
  if ($u->isLoggedIn()) { ?>
    <style type="text/css">
    body { background-position: 0px 49px; }
    </style>
<?php } ?>

If a User is Logged In Do Something

<?php
  $u = new User();
  if($u->isLoggedIn()) {
    echo 'Hello '.$u->getUserName();
  }
?>

If Logged in User is Admin Do Something

<?php
  $u = new user();
  $g = Group::getByName('Administrators');
 
  if ($u->inGroup($g)||$u->isSuperUser()) {
    //do something here
  }
?>

Working With Files and Sets

Get Path to File

<?php
  $f = File::getByID(FILE_ID);
  $fv = $f->getApprovedVersion();
  $path = $fv->getRelativePath();
?>

]

Get File Set Names

<?php
  Loader::model('file_set');
  $fileSets = FileSet::getMySets();
  foreach ($fileSets as $fs) {
    echo fs->getFileSetName();
  }
?>
 
$fs->getFileSetID()
$fs->getFileSetName()
$fs->getFileSetType()

(in view.php)
<?php
  $fileSets = FileSet::getMySets();
  foreach ($fileSets as $fs) {
    echo $fs->getFileSetName();
  }
?>
 
$fs->getFileSetID()
$fs->getFileSetName()
$fs->getFileSetType()
 
(in controller.php
 
<?php
namespace
use FileSet;
use FileList;
 
  $fileSets = FileSet::getMySets();
  foreach ($fileSets as $fs) {
   $filesets('id' => $fs->getFileSetID(), 'name' => $fs->getFileSetName());
 }
?>

Add a File Set

<?php
  Loader::model('file_set');   
  $fs = FileSet::createAndGetSet('FILESET_NAME', FileSet::TYPE_PUBLIC, $uID = false);
?>

<?php  
  $fs = FileSet::createAndGetSet('FILESET_NAME', FileSet::TYPE_PUBLIC, $uID = false);
?>

Get File Attribute Value

<?php
  $f = File::getByID(FILE ID NUMBER);
  echo $f->getAttribute('Attrubute_name');
?>

Add a File Attribute

<?php
  // add file attribute programmatically (text)
  Loader::model('file_attributes');
  $textt = AttributeType::getByHandle('text');
  $attribute=FileAttributeKey::getByHandle('attribute_handle');   	
 
  if( !is_object($attribute) )
    FileAttributeKey::add($textt, array('akHandle' => 'attribut_handle', 'akName' => t('Atribute Name')));
 
 
  // when uploading with a form
  function action_file_upload()	{
    Loader::library("file/importer");
    $fi = new FileImporter();
    $newFile = $fi->import($_FILES['fileName']['tmp_name'],
    $_FILES['fileName']['name']);
 
   // add attriubute   
   if($newFile instanceof FileVersion) {
     $f = $newFile->getFile();
     $fv = $f->getApprovedVersion();			
     $fv->setAttribute('ATTRIBUTE_NAME', 'VALUE');
   }
}
?>

<?php
// in a package
use Concrete\Core\Attribute\Key\CollectionKey as CollectionAttributeKey;
use \Concrete\Core\Attribute\Type as AttributeType;
 
$attribute = CollectionAttributeKey::getByHandle('my_attribute');
if ( !is_object($attribute)) {
  $att = AttributeType::getByHandle('select');
  // add attribute 
  CollectionAttributeKey::add($att, array('akHandle' => 'my_attribute', 
    'akName' => t('My Attribute'), 
    'akIsSearchableIndexed' => true, 
    'akIsSearchable' => true, 
    'akSelectAllowMultipleValues' => true, 
    'akSelectAllowOtherValues' => true, 
    'akSelectOptionDisplayOrder' => 'alpha_asc'),$pkg); 
 
  // or add to attribute and assign to an attribute set
  // CollectionAttributeKey::add($att, array('akHandle' => 'my_attribute', 
  // 'akName' => t('My Attribute'), 
  // 'akIsSearchableIndexed' => true, 
  // 'akIsSearchable' => true, 
  // 'akSelectAllowMultipleValues' => true, 
  // 'akSelectAllowOtherValues' => true, 
  // 'akSelectOptionDisplayOrder' => 'alpha_asc'),$pkg)->setAttributeSet($akCatSet); 
  $addAttribute = CollectionAttributeKey::getByHandle('my_attribute');
}

Add a File Attribute Set

<?php
  use \Concrete\Core\Attribute\Key\Category as AttributeKeyCategory;
 
  $akCat = AttributeKeyCategory::getByHandle('collection');
  $akCat->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
  $akCatSet = $akCat->addSet('my_attribute_set', t('My Attribute Set'),$pkg);

Display / Get File Info from File Sets

<?php
  Loader::model("file_set");
  Loader::model('file_list');
 
  $fs = FileSet::getByName('Your File Set');
  $fl = new FileList();
  $fl->filterBySet($fs);
  $fl->sortBy('fsDisplayOrder', 'asc');
  $files = $fl->get();
 
  foreach($files as $f) {
    echo $f->getFileName();
    echo $f->getTitle(); 
    echo $f->getAttribute("width");
    echo $f->getDownloadURL();
    echo $f->getRelativePath();
    echo $f->getDescription();
    echo $f->getAttribute('attribute_name') 
  }
?>

(in view.php)
<?php
  $fs = FileSet::getByName('Your File Set');
  $fl = new FileList();
  $fl->filterBySet($fs);
  $fl->sortBy('fsDisplayOrder', 'asc');
  $files = $fl->get();
 
  foreach($files as $f) {
    echo $f->getFileName();
    echo $f->getTitle(); 
    echo $f->getAttribute("width");
    echo $f->getDownloadURL();
    echo $f->getRelativePath();
    echo $f->getDescription();
    echo $f->getAttribute('attribute_name');
  }
?>
 
(in controller.php)
<?php
namespace
use FileSet;
use FileList;
 
  $fs = FileSet::getByName('Your File Set');
  $fl = new FileList();
  $fl->filterBySet($fs);
  $fl->sortBy('fsDisplayOrder', 'asc');
  $files = $fl->get();
?>  

Add a File

<?php
    Loader::library("file/importer");
    $fi = new FileImporter();
    $newFile = $fi->import($pathToFile, $nameOfFile, $fileObject);
  }
?>

Add a File From a Form

<?php
  // function in controller
  function action_file_upload()	{ 
    Loader::library("file/importer");
    $fi = new FileImporter();
    $newFile = $fi->import($_FILES['fileName']['tmp_name'],
    $_FILES['fileName']['name']);
  }
?>

Add a File to a file Set

<?php
  // when uploading with a form
  function action_file_upload()	{
    Loader::library("file/importer");
    $fi = new FileImporter();
    $newFile = $fi->import($_FILES['fileName']['tmp_name'],
    $_FILES['fileName']['name']);
 
    // add file to file set		
    Loader::model('file_set');
    $fs = FileSet::createAndGetSet('FILE_SET_NAME', FileSet::TYPE_PUBLIC, 
    $uID = false);
    $fsf = $fs->addFileToSet($newFile);	
  }
?>

Working With Page Lists

Initiating a Page List

<?php
  Loader::model('page_list');
 
  $pl = new PageList();
 
    ... Filtering and Sorting Options ...
 
   // Get the page List Results 
  $pages = $pl->getPage() Get all pages that match filter/sort criteria.
 
  Or
 
  $pages = $pl->get($itemsToGet = 100, $offset = 0) Get pages (taking into account $itemsPerPage, current page, etc...)
?>

(in view.php)
 
<?php
  $pl = Core::Make('PageList'); 
 
  $pl = new PageList();
 
    ... Filtering and Sorting Options ...
 
   // Get the page List Results 
  $pages = $pl->get() Get all pages that match filter/sort criteria.
?>
 
(in controller.php)
 
<?php
namespace
use Concrete\Core\Page\PageList;
 
  $pl = new PageList();
 
    ... Filtering and Sorting Options ...
 
   // Get the page List Results 
  $pages = $pl->get() Get all pages that match filter/sort criteria.
?>

Page List Filters / Sorting

<?php
  // Available Filters
  $pl->ignorePermissions(); // Don't check the permissions of the logged-in user.
  $pl->ignoreAliases(); // Ignore aliased pages.
  $pl->includeSystemPages(); // Include system pages
  $pl->displayUnapprovedPages(); // Include pages that have not been approved.
  $pl->filterByKeywords($keywords); // Filters files by keywords.
  $pl->filterByName($name, $exact = false); // Filter page name.
  $pl->filterByPath($path, $includeAllChildren = true); // Filters pages by path, children true/false
  $pl->filterByParentID($cParentID); //Filters by the parent ID.
  $pl->filterByCollectionTypeID($ctID); //Displays pages of a certain page type.
  $pl->filterByUserID($userID); //Displays pages owned by a particular user ID.
  $pl->filterByIsApproved($isApproved); //Only display approved pages.
  $pl->filterByIsAlias($ia); //Filters by whether an item is an alias or not.
  $pl->filterByCollectionTypeHandle($ctHandle); //Filters by page type handles. $ctHandle can be array of page type handles.
  $pl->filterByDateAdded($date, $comparison = '='); //Filters by date the page was added. $comparison can be any MySQL comparison operator.
  $pl->filterByPublicDate($date, $comparison = '='); //Filters by public date. $comparison can be any MySQL comparison operator.
  $pl->filterByDateLastModified($date, $comparison = '='); //Filters by date the page was last modified. $comparison can be any MySQL comparison operator.
  $pl->filterByNumberOfChildren($number, $comparison = '='); //Filters by number of page children. $comparison can be any MySQL comparison operator.
  $pl->filterByAttribute($attributeKeyHandle, $value, $comparison); //Filters by attribute.
  $pl->filter($column, $value, $comparison); //Filter by MySql "WHERE" clause
 
  // Sorting Options
  $pl->sortByRelevance(); //Orders by index score descending. Only available when searching by keywords.
  $pl->sortByDisplayOrder(); //Orders by sitemap display order ascending.
  $pl->sortByDisplayOrderDescending(); // Orders by sitemap display order descending.
  $pl->sortByPublicDate(); //Orders by public date ascending.
  $pl->sortByPublicDateDescending(); //Orders by public date descending.
  $pl->sortByName(); //Orders by page name ascending.
  $pl->sortByNameDescending(); // Order by name descending
  $pl->sortBy('ak_ATTRIBUTE_HANDLE'); // Order by a page attribute
?>

Get Page List based on Collection Type Handle

<?php
  $pl = new PageList();
  $pl->filterByCollectionTypeHandle('COLLECTION_HANDLE');
  $pl->sortByDisplayOrder('alpha_asc'); // Sort alphebetically
 
  $pages = $pl->getPage();
 
  // Display Page Name and Description
  foreach ($pages as $page){
    echo $page->getCollectionName();
    echo $page->getCollectionDescription();
  }
?>

Embed Page List Block in Theme

<?php
  $bt = BlockType::getByHandle('page_list');
 
  //Set Options
  $bt->controller->orderBy = 'display_asc'; // 'display_asc', 'chrono_desc', 'chrono_asc', 'alpha_asc', 'alpha_desc'
  $bt->controller->ctID = ''; // Filter by Collection Page Type ID
  $bt->controller->displayFeaturedOnly = 'false'; // If Featured Page attribute 'true', 'false' 
  $bt->controller->displayAliases = 'false'; // Display aliase pages 'true', 'false'
  $bt->controller->paginate = 'true'; // 'true', 'false'
  $bt->controller->cParentID = '6149'; // Display pages beneath this page ID
  $bt->controller->includeAllDescendents = 'true'; // 'true', 'false'						
  $bt->controller->orderBy = 'display_asc'; // 'display_asc', 'chrono_desc', 'chrono_asc', 'alpha_asc', 'alpha_desc'
  $bt->controller->showrss = 'false'; // Display RSS feed 'true', 'false'
  $bt->controller->truncateSummaries = 'true'; // 'true', 'false'
  $bt->controller->truncateChars = '128'; // Truncate length if summaries 'true'
  $bt->controller->paginate = 'true'; // 'true', 'false'
 
  // Render the block
  $bt->render('view'); // for template 'templates/template_name'
?>

Re-Sort Page List Block $pages Array

<?php
  // Re-sort in view.php by an end date page attribute
  usort($pages, create_function('$a, $b', 'return $a->getAttribute("end_date") > $b->getAttribute("end_date");'));
?>

Controllers

Single Page Controllers

Create single page file: applications/single_pages/test_page.php
 
Create a controller file: applications/controllers/test_page.php 
 
Namespace and class for controller
 
<?php 
namespace Application\Controller\SinglePage;
use PageController;
 
class TestPage extends PageController
{
 
    // Add functions
    public function view()
    {
        // Whatever code you need for functions
        echo 'Hello World';
    }
 
}
?>

Database

Fetch Data From Database

<?php
  $db = Loader::db();
 
  $sql = "SELECT * FROM [table] WHERE [column1] = ? AND [column2] = ?";
  $vals = array('[value1]', '[value2]');
  $r = $db->Execute($sql, $vals);
  $row = $r->FetchRow();
 
  echo $row[column name];
?>

Update Database

<?php 
  $db = Loader::db();
 
  $sql = "UPDATE [table] SET [column] = ? WHERE bID = $this->bID";
  $vals = array('[value]');
  $update = $db->Execute($sql, $vals);
?>

Helpers

Date/Time Helper

Load Date/Time Helper

<?php
$date = Loader::helper("date");
?>

<?php
$date = Core::make('helper/date');
?>

Compare Today's Date With a Pages Date/Time Attribute (end_date) And Do Something

Using Date Helper to format ($mask=) display of date and time.
 
<?php
 
  if($date->getSystemDateTime($c->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';
  }
?>

Display Date/Time In dd-mm-yyyy 00:00 Format.

<?php
  $date = Loader::helper("date");  echo $date->getLocalDateTime('now',$mask = 'd-m-Y G:i')
?>

Display Page Attribute "end_date" In mm/dd/yy Format

<?php
  echo $date->getSystemDateTime($c->getCollectionAttributeValue('end_date'), $mask = 'm/d/y') 
?>

Get Date The Page Was Last Edited

<?php
  foreach($c->getBlocks('Main') as $b) {
    $bDate[$i] = $b->getBlockDateLastModified();
    $i ++;
  }
 
  rsort( $bDate );
 
  echo $date->getLocalDateTime($bDate[0],$mask = 'm-d-Y g:i:s');
?>

If Page Attribute "end_date Is Greater Than Current Time, Do Something.

<?php
  if($date->getSystemDateTime($c->getCollectionAttributeValue('end_date'), $mask = 'd-m-Y G:i') > $date->getLocalDateTime('now',$mask = 'd-m-Y G:i')) {
 
    [do something here]
 
  }
?>

PHP Date Formatting For Mask

a 'am' or 'pm'
A 'AM' or 'PM'
B Swatch Internet time
d day of the month, 2 digits with leading zeros; i.e. '01' to '31'
D day of the week, textual, 3 letters; i.e. 'Fri'
F month, textual, long; i.e. 'January'
g hour, 12-hour format without leading zeros; i.e. '1' to '12'
G hour, 24-hour format without leading zeros; i.e. '0' to '23'
h hour, 12-hour format; i.e. '01' to '12'
H hour, 24-hour format; i.e. '00' to '23'
i minutes; i.e. '00' to '59'
I (capital i) '1' if Daylight Savings Time, '0' otherwise.
j day of the month without leading zeros; i.e. '1' to '31'
l (lowercase 'L') day of the week, textual, long; i.e. 'Friday'
L boolean for whether it is a leap year; i.e. '0' or '1'
m month; i.e. '01' to '12'
M month, textual, 3 letters; i.e. 'Jan'
n month without leading zeros; i.e. '1' to '12'
r RFC 822 formatted date; i.e. 'Thu, 21 Dec 2000 16:01:07 +0200' (added in PHP 4.0.4)
s seconds; i.e. '00' to '59'
S English ordinal suffix, textual, 2 characters; i.e. 'th', 'nd'
t number of days in the given month; i.e. '28' to '31'
T Timezone setting of this machine; i.e. 'MDT'
U seconds since the epoch
w day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday)
Y year, 4 digits; i.e. '1999'
y year, 2 digits; i.e. '99'
z day of the year; i.e. '0' to '365'
Z timezone offset in seconds (i.e. '-43200' to '43200'). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.

Image Helper

Load Image Helper

<?php
  $imageHelper = Loader::Helper('image');
?>

(depricated)

<?php
  $imageHelper = Core::make('helper/image');
?>

Output Thumbnail from Page Attribute

If image exists in Image/File Attribute "product_image", display the image scaled to 100px.
 
<?php
  if($c->getAttribute('product_image')) {
    $imageHelper->outputThumbnail($c->getAttribute('product_image'),100 ,100);
  }
?>

Get Thumbnail Info with Image Helper

<?php
  $file = File::getByID(id_number);
  $img = $imageHelper->getThumbnail($file, 100, 100);
?> 
 
<img src="<?php echo $img->src; ?>" width="<?php echo $img->width; ?>" height="<?php echo $img->height; ?>">

Multilingual Helper

Load Multilingual Helper

<?php
  $lh = Loader::helper('section', 'multilingual');
<?

Return Two Language Code

<?php
  $lh = Loader::helper('section', 'multilingual');
  echo $lh->getLanguage();
?>

Site.php

Common Settings

Set advanced permissions on
  define('PERMISSIONS_MODEL', 'advanced');
 
Use APC Caching (you need APC installed)
  define('CACHE_LIBRARY', 'apc');
 
Disable Zend Cache Cleaning (may improve performance)
  define('CACHE_FRONTEND_OPTIONS',
  serialize(array('automatic_cleaning_factor' => 0)));
 
Set time to 24 hour format
  define('DATE_FORM_HELPER_FORMAT_HOUR', '24');
 
Date Formatting
  define('DATE_APP_GENERIC_MDYT_FULL', 'F d, Y \a\t g:i A');
  define('DATE_APP_GENERIC_MDYT', 'n/j/Y \a\t g:i A');
  define('DATE_APP_GENERIC_MDY', 'n/j/Y');
  define('DATE_APP_GENERIC_MDY_FULL', 'F d, Y');
 
Change minimum user name length from default value 3
  define('USER_USERNAME_MINIMUM', 3);
 
Change maximum username length from default value 64
  define('USER_USERNAME_MAXIMUM', 64);
 
Change minimum password length from default value 3
  define('USER_PASSWORD_MINIMUM', 5);
 
Change maximum password length from default value 64
  define('USER_PASSWORD_MAXIMUM', 64);
 
Change session time from default of 2 hours
  define('SESSION_MAX_LIFETIME', 7200); // 2 hours
 
Set registration email notification address
  define('EMAIL_ADDRESS_REGISTER_NOTIFICATION',
  'example@domain.com');
 
Set registration email notification from address
  define('EMAIL_ADDRESS_REGISTER_NOTIFICATION_FROM',
  'example@domain.com');

White Label Configuration

Disable concrete5 marketplace integration.
define('ENABLE_MARKETPLACE_SUPPORT', false); 
 
Disable help searches in the intelligent search.
define('ENABLE_INTELLIGENT_SEARCH_HELP', false);
 
Disable marketplace add-ons appear in intelligent 
search results. 
define('ENABLE_INTELLIGENT_SEARCH_MARKETPLACE', false); 
 
Disable newsflow
define('ENABLE_NEWSFLOW_OVERLAY', false);
 
Path to the logo image. This can also be a full URL. 
This file should be 49x49 pixels.
define('WHITE_LABEL_LOGO_SRC', 'PATH TO FILE'); 
 
Alt text for the logo
define('WHITE_LABEL_APP_NAME', 'TEXT');
 
Disable Layouts.
define('ENABLE_AREA_LAYOUTS', false); 
 
Disable Custom Design for blocks or areas.
define('ENABLE_CUSTOM_DESIGN', false);
 
Disable Newsflow connect to concrete5.org to retrieve 
latest updates. 
define('ENABLE_APP_NEWS', false); 
 
Set to a valid image (either local or a remote URL), or none.
define('WHITE_LABEL_DASHBOARD_BACKGROUND_SRC', 'none');
 
Web address for today's Image
define('WHITE_LABEL_DASHBOARD_BACKGROUND_FEED', false); 
cheatsheet.txt · Last modified: 2017/03/15 20:28 by admin

Page Tools

User Tools