More Frog CMS Magic
Over the weekend I was working working on a small website build that required a simple CMS so I decided to put Frog CMS to use again; it continues to impress me. What at first looks like a very simple CMS actually has a powerful API behind it.
First thing I had to do (for my own sanity) was move the layout template outside of the CMS and into an external file. This gives you 2 advantages, you get to use whatever code editor you usually use to edit the template, and the file is then exposed so it can be committed to version control like any other file. It is simple to do with some very basic PHP:
1 2 3 <?php include($_SERVER['DOCUMENT_ROOT'] . "/public/themes/yout-theme-directory/layout-template.inc.php"); ?>
Paste that code in to your layout with a content type of “text/html” and you are done.
1 2 3 4 5 6 7 8 9 10 11 12 13 <?php if(url_match('/')): $bodyID = "home"; else: $bodyID = "page-". $this->slug(); endif; if($this->parent() && $this->parent->slug()=="services"): $bodyClass = "event"; else: $bodyClass = ""; endif; ?>
The first if else statement simply sets the home ID to “home” then every other page to “page-slug-name-here” (slug is set in the ‘Meta’ tab). The second one I use on ‘article’ pages; it simply says if the current page has a parent and its parent is the services page add a class of “event”. So now I can style every article page in the same way, and it’s safe for a client to add event pages themselves.
You may ask why the “$this->parent()”; this is to stop the site breaking when you hit the home page since the homepage has no parent, it is the parent of all other pages.