Sign In  |  Cart  |  Join Now

Understanding and Building Themes in Concrete

Screencast on building themes.   

   Launch>

 

When you add a page in concrete5, you MUST choose a Page Type. A typical concrete5 install contains several page types, which define several editable areas. There can be many areas attached to a particular page type. Typical areas might be "Main Content," "Sidebar," "Header," or "Header Image." Developers can easily define new Page Types through the Site Dashboard, along with typical meta information attached to those types of pages, and a thumbnail to represent the page type.

Themes are collections of Templates. Themes each get their own sub-directory in the /themes/ directory. Each Theme can contain its own sub-directories to store images, css, PHP include files, etc. If as a developer you've chopped your basic layout into HTML, that entire directory is most likely going to become a Theme with a unique Template file for every Page Type in your site. Think of Templates as the View in Model/View/Controller development, and think of the Theme as a package of Templates. Templates take the same name as the page types they match, with a ".php" as their suffix. For example, if you've added a page type to your site with the handle "product_detail," then your theme should likely contain the "product_detail.php" template, unless you're SURE that this particular theme will never need to be mapped to a product detail page.

Finally, when rendering a page, concrete5 (the Controller if we're following MVC thinking) looks at the instance of a created Page to determine which Theme it's using. concrete5 then looks in that Theme directory for a Template filename that matches the Page Type. If none exists, it chooses the default.php template which is the only required file in any Theme.

What should be a Page Type, what should be a Theme?

There's no absolute right way of breaking these up. In earlier versions of concrete there were only Page Types, and we found a lot of sites would end up of a couple of dozen redundant ones (ie: article blue, article green, etc.) With concrete5 we took the opportunity to create a matrix relationship which you can use to solve many problems in many ways.

When we decide how to build sites, we tend to think in these lines:

First, what wireframes do we have for this design? Looking at that documentation, are there unique data requirements for one page versus another. If so, they should absolutely be unique Page Types. If we see About Pages, Product Pages, and Press Releases in a site map, it's easy to assume they'll need to be unique Page Types because not only will they likely look different from one another, but they'll actually have unique data like Size or Color for Product, or Date and By-line for Press Release. So we'll pul out everything that must be unique, and see whats left.

In the remaining wireframes, what is being described as unique that might from a data model prospective, might be the same. There is little difference to a programmer in an About Page and a Services Page if they are both just long columns of text with a side nav area. If you can look at all the instances and say "gee, they might want to add this type of page elsewhere as the site grows, with no changes beyond cosmetic" than it is quite likely you're looking at one Page Type with a couple of Themes.

If you are building an extension to concrete5 that might need a few unique data views (ie: a forum) than you will most likely define Page Types for your application views and let other people customize that data presentation with Themes.

Too many Page Types in a typical install make it difficult to keep track of what type of page you're supposed to add where (although this can be limited with advanced permissions.)

It also tends to make it difficult to do site wide edits later. You can add a block to the Page Type from the Dashboard in concrete5, so every instance of that Page Type will have a copy of that block added instantly. This bulk apply ability is powerful, but means some planning as to what those eventual expectations will be has to go into determining what really needs to be a unique Page Type.

How do Themes and Page Types work?

When loading a page, first the theme for this particular page is determined. Then, a template file corresponding to that page's current page type is applied, if one exists in that theme's current directory. If a matching filename cannot be found, "default.php" is loaded.

The template file is HTML, CSS and PHP. It includes short PHP calls that define the block areas that exist for the page type.

Typically a developer will chop their design into static HTML files with a few images and layout directories as a first step. With concrete5 the whole directory structure can be dumped wholesale into a new theme directory and quickly added to the site.

  1. Chop your site into a working HTML directory.
  2. For every page type in this theme, create a "my_page_type.php" template file in the directory.
  3. Within this template, make sure all stylesheets in your theme are referenced with

    $this->getStyleSheet('your_stylesheet.css');

  4. Within your templates, make sure that all images and files in your theme are prefixed with

    $this->getThemePath();

  5. If desired, add a 120x90 thumbnail graphic to this directory. This file should be named "thumbnail.png"

  6. Add "description.txt" to your theme directory. The title of your theme should go on the first line, the description of it on the second.
  7. Create a directory in "/themes" for your new theme.
  8. Upload the complete contents of your chop to /themes/new_theme."
  9. Enter the "themes" section of the concrete5 dashboard.
  10. On the themes page in the dashboard, you should see your theme, with its title and thumbnail image, in a section of the page titled "Themes Available to Install."
  11. Click the install button next to your theme.
  12. When your theme is installed, you should be redirected to a second step, entitled "Inspect Theme." Here, you will be able to automatically create page types for any special template files found in your theme. If your theme doesn't currently contain any special template files, you can click "Return to Themes."
  13. Your theme will be installed and should be listed with any others that are available to use on your site.
  14. To activate your theme to use throughout your entire site, click the "Activate" button. You will have to confirm your choice. (**Note: This action cannot be undone and will overwrite any custom theme choices on particular pages that may have been set.)

If you wish to remove a theme at any time, you may click the remove button next to its thumbnail. This will remove the theme from the concrete5 dashboard, and move its directory to the "files/trash/" directory.

Now, whenever you click the design button when editing a page, your theme's thumbnail should appear in the theme scroller, and you should be able to apply it to any page in your site.

Advanced Topics

Introduction to Themes Screencast

Learn how to translate a simple HTML theme found on the web into a C5 theme, in under 8 minutes.

Keep Themes from Interfering with concrete5 Styles

A simple trick to make your themes less likely to interfere with the core concrete5 styles.

Enabling Style Customization in Your Theme

concrete5 includes a powerful way to offer custom styles to clients and developers alike. Here's how your can setup your themes to take advantage of this.

Themes as Applied to Single Pages

Templates as Views: Helpful Functions For Use Within Your Templates

Specifying Themes by Path Using "site_theme_paths.php"

Order of Precedence When Assigning a Theme to a Page

A list of areas and page types for themes

A list of all the common area names and page types that we currently have in C5. You can name a page type and an area anything – but if you use common names your themes will be more easily interchangeable with other themes.

Converting a site into a theme

A brief how-to on turning an existing site design into a Theme in concrete5.

Submitting a theme to the concrete5 marketplace

You've got a theme - now you want to make it available to the world. Here are some guidelines you should follow.

Comments:

jstew
Posted by jstew on
I am having trouble removing page types after they have been installed. The page types are no longer in use and I wish to delete them entirely, yet I seem to be having problems getting rid of them through the dashboard. Any ideas? Can I manually delete these?
jstew
Posted by jstew on
This fixed it in 5.2 RC1
http://www.concrete5.org/community/bugs/dashboardpagestypescontroller_spelling
PaulWood
Posted by PaulWood on
Hey I noticed that you guys added a "Customize Theme" section in your default Template. Is there a file some where that I could play with so I could make this section more extensive? I noticed your tagging the regions in the main CSS. I'm planning on building more advanced templates and giving them away to the community for free. I love what you guys are doing and want to help keep C5 growing.
Posted by mildavw on
Step 2 should should indicate that a page type of "default.php" is required.
Posted by mildavw on
Shouldn't step 4 be: $this->getThemePath(); ?
plschneide
Posted by plschneide on
I had the same question. In the video a different command is used for the CSS and for the images. In this doc I tried the command listed here and it didn't work. I tried what was in the video and it did. Is there just typos or is it something else?

Also it wasn't noted that you need an echo/print before the statement, which would have been helpful.
willm
Posted by willm on
Ive just installed C5 but when I duplicate an existing theme as the basis for customising my own, nothing appears on the Themes page for me to install. The only ones I get are Plain Yogurt and Greensalad. Help!?

Im definitely uploading to the correct directory - for example I can change the .png thumbnails and see the changes when I refresh. But if I change the description.txt of the exiting themes, nothing happens?

Any help appreciated.

ps. I also get the error at the bottom of the page:

Get More Themes
Unable to connect to the marketplace.
willm
Posted by willm on
Ah dont worry - I was uploading into the core themes folder inside /concrete/ instead of the empty themes directory above... ;-)
Posted by richoid on
So, once I've developed my own theme... I want to get rid of the original themes. My clients will just get confused if I leave 'em in there.

How's the best way to do this?
proteuscreative
Posted by proteuscreative on
richoid, I believe you can just remove them from the dashboard under the pages and themes section. Just click the "Remove" button for the given theme.

I have a question regarding themes and page types—can you upload a page type template after the theme for that template has already been installed? Or would you have to go back and re-install the entire theme with all the page types you want to have?
frz
Posted by frz on
you can always add a template file to a theme in the file system. If you've made a page type with a matching handle, that file will be used for its display, otherwise default.php will.
Floris
Posted by Floris on
I'm experimenting a bit with themes, and I have a question: is it possible to ad one or more blocks to a Page Type? So that if you choose the Page Type, the blocks are automaticly inserted into the page.
It must be possible, because if I work with the Plain Yoghurt theme, header navigation and a banner image are automaticly insterted.
Can anyone tell me how to do it? Thanks a lot!!
frz
Posted by frz on
yes:

http://www.concrete5.org/help/editing/scrapbook_defaults/
Floris
Posted by Floris on
Thank you for your fast reaction!! Now it's all crystal clear.
Posted by jasonrwd on
FYI to Concrete admins, this guide lists #1 on Google for "create a concrete5 theme", yet Steps #3 and #4 seem to have been replaced with a new command:
Posted by jasonrwd on
Woops, too much code.

$this->getThemePath()
andrew
Posted by andrew on
@jasonrwd - that is correct. We used to use getThemePath() and that command will still work, but getStyleSheet is a bit better, because you can include in those stylesheets some style rules that will let your stylesheet be customizable through the dashboard. This will only work if your theme's stylesheet is called with getStyleSheet.
Posted by jrobinson on
I've hacked together a few themes but haven't seen any reference to this line:

defined('C5_EXECUTE') or die(_("Access Denied."));

I'm assuming that this is basically saying... "only execute this file within c5"?

I see it in the custom block example and in the themes that ship with c5 but nothing in the tutorials about it. Any explanation would be great!
andrew
Posted by andrew on
That's correct - if this file is accessed directly (rather than being included by concrete5) it should exit with the "access denied" error. And that should happen for all files except index.php, since everything runs through index.php

Good message - we'll try and put a notice about it somewhere in a tutorial.
mhaenlin
Posted by mhaenlin on
Found a content error in the following section above:

"How do Themes and Page Types work?"

Point 4 says to place

$this->getViewPath();

before images etc. It's actually:

$this->getThemePath();

Took me a little searching to find that and get my theme to render properly.
mhaenlin
Posted by mhaenlin on
Found a content error in the following section above:

"How do Themes and Page Types work?"

Point 4 says to place

$this->getViewPath();

before images etc. It's actually:

$this->getThemePath();

Took me a little searching to find that and get my theme to render properly.
frz
Posted by frz on
correct... fixed.
hereNT
Posted by hereNT on
"If a matching filename cannot be found, "default.php" is loaded."

This is somewhat incorrect - if the page type is from a package, the contents of the page type will be rendered in the view.php's inner_content just like a single page.

If it's just a page type that doesn't have a package connected, it uses default.php...
You must be logged in to leave a reply.
 
 

Hot Spots...

ForumsPartners | Contact | Blog

Search site