From Habari Project

Jump to: navigation, search

IsContent is an interface in Habari that allows a class to be defined as providing renderable content.

How to render objects that implement IsContent

Assuming that a variable contains an object that implements IsContent, the theme system can easily render that content using code like this:

// This code appears in a theme template, like home.php
foreach($posts as $post): 

In the above sample, the $post variable is an instance of the Habari core Post object. This object implements IsContent. When $theme->content($post); is called, the theme system searches for the appropriate template to render the value of $post.

If $post is an Entry, then the theme looks first for a template named "entry.php". If that template does not exist, then it looks for "post.php".

Each type of object will have its own set of fallback templates. This is defined by the object that implements IsContent, and is the main feature of the IsContent interface.

In the template that is displayed, the value that is passed is reassigned to the variable $content. So to render the title of the post passed to $theme->content($post), the template would need to include:

<?php echo $content->title; ?>

Trying to use the original variable name may result in a PHP error.

How to create an object that implements IsContent

Habari core classes that implement IsContent

  • Post
  • Comment
  • Block
Personal tools