-
Notifications
You must be signed in to change notification settings - Fork 1
M.H.L.P
What is M.H.L.P?
M.H.L.P stands for Model, Helper, Library, Partial.
See the Coding Standards section for how to properly name your models.
Your theme may require data from other services in your tempaltes, possibly even custom queries agains the database. Rather than handling this inline or modifying the core models you can load models in your themes.
A really good example of a template model might be API interactions like in the Serpent API.
class git_model {
public function download()
{
if ( !defined( 'CHECK_TIMEOUT') ) define( 'CHECK_TIMEOUT', 5 );
$scc = stream_context_create( array( 'http' => array( 'timeout' => CHECK_TIMEOUT ) ) );
$git_downloads = file_get_contents( 'http://api.tentaclecms.com/version/', 0, $scc );
$git_downloads = json_decode( $git_downloads );
return $git_downloads;
}
}
You can call your model like this
$git = theme::model('git');
$download = $git->download();
Every theme will look for and load your functions.php
file. Helpers are in many ways reusable chunks of code. If your theme requires a set group of helpers to be loaded you could do so in your functions.php
.
All of your helpers must be located in a folder in your theme called helper.
- /theme/
- /theme/helpers/
- /theme/helpers/file.php
Loading a helper:
theme::helper('file');
Your theme could require a PHP library that is not included by default.
All of your libraries must be located in a folder in your theme called library containing a folder with the library code inside.
- /theme/
- /theme/library/
- /theme/library/folder/file.php
Loading a library
theme::library("folder","file");
Partial ( See Template Structure )
To load a part you can call theme::part( 'name' );
from any file, including other parts. Parts can accept an array of data theme::part( 'name', array('title'=>'My Home Page', 'assets'=>'default'))
This will make $title
and $assets
available in your part.
Objects and Arrays can also be passed to parts array('array_data'=>$array)
Some common parts would include header, footer, and sidebar
- part-header.php
- part-footer.php
- part-sidebar.php
To help keep your theme organized you can keep your partials in a folder like this theme::part( 'partials/name' );
.