page_theme.php not working in my custom theme

Permalink 2 users found helpful
I had trouble getting my page_theme.php customizations to work until I realized that I was setting up my themes incorrectly and this was not allowing the page theme class to load. Although some of this may be obvious or described elsewhere, I'm posting this in case anyone else runs into the same problem.

When creating a theme, in description.txt, be sure the name of the theme on the first line agrees with the name of the folder the theme is loaded in (e.g. in description.txt use "Hornet" for the theme that's loaded at application/themes/hornet. Do not use a non-matching name like "My Beautiful Hornet Theme" in description.txt. Use all lower case characters for the theme folder name.

If the theme name includes spaces, represent these as underscores in the folder name. So in description.txt the theme named "Green Hornet" should be in folder application/themes/green_hornet.

When using page_theme.php to set up awesome customizations for your theme start with a simple file (example below) or copy the file from one of the included themes in concrete/themes and remove the functions and features you don't need.

IMPORTANT: change the namespace line at the very top of the file so it matches your custom theme. For our example it would look like:

namespace Application\Theme\Hornet;
use Concrete\Core\Page\Theme\Theme;
class PageTheme extends Theme {
   protected $pThemeGridFrameworkHandle = 'bootstrap3';
   public function registerAssets() {
      $this->requireAsset('javascript', 'jquery');

When your theme name includes a space namespace line should be CamelCase [thank you jakobfuchs]:
namespace Application\Theme\GreenHornet;

Be sure nothing appears before the namespace line, aside from the <?php line.

Finally, if you are adding page_theme.php to an existing, enabled theme you can't just upload it and expect it to work. On your site enable a different theme, REMOVE the theme you're adding page_theme.php to (use the red Remove button), and then, with page_theme.php now uploaded, install the theme again and reactivate it. That will tell C5 that page_theme.php is part of your theme. This has been mentioned elsewhere more than once; I'm just including it here for compleness.

Hope this helps.

View Replies:
jakobfuchs replied on at Permalink Reply
Two small things. I am pretty sure you can name your theme whatever you want in your description.txt (not that it matters much). The namespace rule is always to camel case the theme name ( "my new theme" becomes MyNewTheme and the folder the theme resides in should be called my_new_theme).
stuball replied on at Permalink Reply
Thank you. I assumed that the namespace to use was derived from the theme name shown in description.txt, but in truth I changed both the theme path to lower case and the theme name simultaneously, so you may well be correct.

I corrected my post to indicate camel case for the theme name. Thanks!
serdarde replied on at Permalink Reply
You saved my time, thank you
heathgriffin replied on at Permalink Reply
I know this is in the old forum, but I can confirm this works for 8.1 development as well. Thank you for a great explanation of how this works and how to implement it.