Humblee

A humble PHP framework & CMS

Templates

There are two main types of templates in Humblee. Site templates, which contain the outer HTML common to all pages, including the opening and closing <html> tags, <head> code and possibly the main navigation and footer. Page templates generally contain the HTML layout for the main body of the pages using that template.

Site Templates

By default, Humblee has a boilerplate site template located at ~/application/views/templates/template.php which should be modified to fit your needs. The contents of this file can be wholly replaced with your own HTML but must include a snippet of PHP to include the inner page template. At a minimum, your site template should look like this:

<!DOCTYPE html>
<html>
 <head></head>
 <body>
   <?php echo (isset($template_view)) ? $template_view : '' ?>
 </body>
</html>

Page Templates

Most pages of the site use the "default" page template located at /application/views/default.php but you can create as many different page layout templates as needed. Again, you can add as much HTML as you would like to the view but, if the page will be rendering content entered from the CMS, the view must include PHP code to output the content blocks used on this page. A sample page template may look like this:

<div class="banner-image">
 <img src="<?php echo $content['banner_image']->content; ?>">
</div>
<article>
 <?php 
  Draw::content($content,'pagebody');
 ?>
</article>

Drawing Content

Templates are passed several variables, including the objects containing information about the given page and all of the page's content. The $content variable is an array containing objects for each content block used in the page. In the above page template example, the first block of PHP code is echoing the content value of the "banner_image" content block. In this case, that content is the path to an image URL that was entered through the CMS. The $content['banner_image'] object would also contain any other information stored in the database relating to that particular block of content for this page. For example you echo $content['banner_image']->publish_date to see the timestamp of when this content was last updated.

The second PHP snippet in the above page template example code utilizes a the helpful static method, Draw::content(), which outputs the content for a given content block in the $content array; in this case, the "pageBody" content block. In addition to being slightly easier to type, using this method has the added benefit of wrapping the content in additional HTML for use with the front-end content editor, if enabled.

The Draw class also has a special method for outputting all of the SEO <meta> and open graph tags for a given page if you are utilizing the "SEO" content block widget. In your outer site template file you can use Draw::metaTags() to automatically echo the page's title, description and special open graph meta data. For example:

<!DOCTYPE html>
<html>
 <head>
  <?php Draw::metaTags($content); ?>
 </head>
 <body>
   ... your site here
 </body>
</html>

Register New Page Templates

In order for pages added through the CMS to use a newly created page template it must be added through the "Manage Templates" tool in the CMS. This tool requires the "designer" or "developer" role.

If the page template has no special functionality beyond showing static or CMS generated content and if it will be wrapped in the default site template, then select the "passed to default controller" method and enter the name of the new page template in the "custom view path" field. Note that this field assumes your view file lives in the ~/application/views folder and ends in .php. If you've added your view to a subfolder, include the folder name. For example, if your page template is in ~/applications/views/subfolder/my-page-template.php enter the "custom view path" as "subfolder/my-page-template"

If, however, the page view requires additional functionality or uses a different site template then you will need to create a custom controller in ~/application/controllers. For example:

<?php
class Controller_MyCustomController extends Core_Controller_Template {

  public function index(){

    // pass the result of whatever special functionality this
    // controller was created for.
    $this->something_special = "";  

    // optionally don't use the default site template
    $this->setTemplatePath('application/views/templates/special-site-template.php');

    $path_to_my_page_template = _app_server_path . 'application/views/my-page-template.php';
    return $this->template_view = Core::view( $path_to_my_page_template,get_object_vars($this));
  }
}

Then, in the "Templates Manager" select the "Hard coded in a custom controller" method and enter the name of this new controller and set the "action" field as the function to be called. In the above example, that would be "index"