PHaiku

Templates

To desambiguate I will call theme a template as a whole directory of files and template a separate php file that is used to render content.

The themes are located in the ./templates directory. The default theme is Skela and it's based on the Skela 1080px grid system.

You can use and modify Skela which tends to be as agnostic as possible, so that it's easy to modify it with your own styles.

However, it's also easy to implement any of the html templates you can grab on the web, or create your own.

Basic concepts

Templates are php files. For basic usage you need at least index.php. This file can include other files (like header.php, footer.php and aside.php ...). To include dynamic content, you simply echo object properties that are defined in the code or include other files.

<?php  include("header.php"); ?>
<div class="row">
	<div class="content fourteen columns">
		<?php echo $page->content;  ?>
	</div>
	<aside class="four columns">
		<?php include 'aside.php';?>
	</aside>
</div>
<?php include("footer.php"); ?>

Variables

The variables you include in templates are simple object properties you access as $object->property. There are three objects available by default: $site, $page and $widgets. Bellow is their description and a list of properties they contain by default:

  • $site contains properties that are valid site wide.
    • $site->language - contains the two letter language code of the current language. You need this mainly to set the language in the header section. It's defined by the PHaiku::setBasicData() method.
    • $site->title - contains whatever you set in the _config.php file, used for setting the content of the <title> tag. You can use it also to set the main heading of the site or anywhere else.
    • $site->baseurl - contains the base url which is the root url of your PHaiku installation.
    • $site->template_url - contains the url of the current template. It's extremely usefull for setting the correct urls for css, javascript and image inclusions. Example:
      <link rel="stylesheet" href="<?php echo $site->template_url; ?>/css/custom.css">
      It's defined by the PHaiku::setBasicData() method.
  • $page contains properties related to the current page being served. Currently there's only one predefined:
    • $content - holds the main content of the current page (whatever content you create in your .html files). It's defined by the handler that handles the current request.
  • $widgets contains all the widgets by the names you give them. Two are predefined by default:
    • $widgets->menu contains the main menu as defined by the PHaiku::setMenu() method.
    • $widgets->langmenu contains the language menu if you use the multilingual version. It's defined by the PHaiku::langMenu() method.

Define custom variables

The easiest way to define custom variables is defining them in the _config.php file(s).

The variables defined this way are available in the $site object. This is usefull to define things like footers, site slogans and in the case of multilingual sites, it's the place to define common language strings, since there's a _config.php file present in every language folder for the language in question. Example _config.php file contents:

return [
	"title" => "PHaiku",
	"slogan" => "brief and efficient",
	"copyright" => "(c) 2014 gresak.net",
	"more" => "More to comme ..."
];

You can also define variables in the object $widgets by defining widgets, or define them in your custom made handlers.

Objects that define variables are of type \PHaiku\Data that extends the php's stdClass(). The extension uses a magic __get() method to return an empty string on non defined properties. For this reason, you don't have to worry if your template has any undefined properties.

That's all there is to templates.

Comments

Feel free to comment or ask questions! Thanks!

comments powered by Disqus

Execution time: 0.0299s Memory usage: 0.676MB