Skip to content

Instantly share code, notes, and snippets.

@robbiegod
Last active April 22, 2016 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbiegod/3c8c235ee18a06b5badd to your computer and use it in GitHub Desktop.
Save robbiegod/3c8c235ee18a06b5badd to your computer and use it in GitHub Desktop.
Concrete5 - common code

Concrete5 v5.5.2.1 Common Code Snippets 💥

==========================================

######Output path to theme location <?= $this->getThemePath(); ?>

######Load the required header file <?= Loader::element('header_required'); ?>

######Benefits

  • remove title tag - dynamically handled by the header file
  • remove meta tag for charset

#####Load the required footer file <?= Loader::element('footer_required'); ?>

######Benefits

  • add C5 tracking code into the footer if enabled
  • load some javascript files into the footer.

By adding both of these, you'll also see the Edit toolbar while on the site when you are logged in.

Add Global Editable Areas (Global)

<?php $a = new GlobalArea("Site Logo"); $a->display(); ?>

Add Editable Content Areas (Per Page)

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

NOTE: $c is current page object and its already setup for you, you just have to remember to add it in there when using Areas.

Load the contents from one area to another section

$c = Page::getCurrentPage();
$pagePath = $c->getCollectionPath();
$sourcePage = Page::getByPath($pagePath);
$sourceArea = new Area('Name of Source Area');
$sourceBlocks = $sourceArea->getAreaBlocksArray($sourcePage);
$outputArea = new Area("Name of Output Area");
$outputArea->disableControls();
$outputArea->display($c, $sourceBlocks);

_NOTE: Thanks to this guy: http://www.concrete5recipes.com/tricks/display-blocks-from-another-area-or-page _NOTE: modified to load the section from whatever page you are currently on.

Elements (these are like includes)

Create a folder called 'elements' inside of your theme folder.

<?php $this->inc('elements/header.php'); ?>

<?php $this->inc('elements/footer.php'); ?>

NOTE: Copy the content of the top part of your template and put it in your header.php file.

NOTE: Copy the content of the bottom part of your template and put it in your footer.php file.

Am I in edit mode?

<?php global $c; if($c->isEditMode()) { ?><p>Check if i am in edit mode.</p><?php } ?>

Am I logged in?

<?php global $u; if($u->isLoggedIn()) { ?><p>Check if i am logged-in.</p><?php } ?>

View.php

create by duplicating the simplest page template and rename the copy to view.php. Delete the main content from the page and replace it with this line of code. Wherever you have this line of code is where the content from the single page will be injected.

<?php print $innerContent; ?>

Load custom page attributes

$custom_page_atttribute = $c->getAttribute('name_of_custom_page_attribute');

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