Overview

Namespaces

  • Sleepy
  • Module
    • Authentication
    • CSV
    • DB
    • FormBuilder
    • FSDB
    • IP2Country
    • Mailer
    • MobiDetect
    • Navigation
    • StaticCache
  • PHP

Classes

  • Debug
  • Hook
  • Router
  • SM
  • Template

Exceptions

  • RouteNotFound
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Class Template

Provides templating functionality

Usage

PHP file: index.php

require_once('include/sleepy.php');

    $page = new Template('templates/default.tpl');
    $page->bind('title', 'Sleepy Mustache');
    $page->bind('header', 'Hello world!');
    $page->show();

Template file: \app\templates\default.tpl

<html>
        <head>
            <title>{{ title }}</title>
        </head>
        <body>
            <h1>{{ header }}</h1>
            <p>This page has been viewed {{ hits }} times.</p>
        </body>
    </html>

Changelog

Version 1.7

  • Updated private prefix (_) for consistency
  • Updated documentation

Version 1.6

  • No longer dependant on Hooks Module
Namespace: Sleepy
License: http://opensource.org/licenses/MIT
Author: Jaime A. Rodriguez hi.i.am.jaime@gmail.com
Version: 1.7
Todo: add #if
Date: June 18, 2016
Located at class.template.php
Methods summary
public
# __construct( string $template = '', string $basedir = '' )

The constructor

The constructor

Parameters

$template
The name of the template
$basedir
The base directory for template files
private Bool
# _checkTemplate( string $file )

Does the template exist?

Does the template exist?

Parameters

$file
Name of template

Returns

Bool
True if template exists

Private

private mixed
# _assignArrayByPath( array $arr, string $path )

Given a path, the function returns a piece of $arr. For example 'name.first' will return $arr['name']['first']

Given a path, the function returns a piece of $arr. For example 'name.first' will return $arr['name']['first']

Parameters

$arr
An array to search using the $path
$path
A path representing the dimensions of the array

Returns

mixed
A sub-array or string

Private

private string
# _render( string $template, array $data )

Renders the template

Renders the template

Parameters

$template
The template to render
$data
The data bound to the template

Returns

string
The rendered template

Private

private string
# _parseTemplate( )

Parses the template after it's been setup

Parses the template after it's been setup

Returns

string
The rendered template

Private

public
# setTemplate( [type] $file )

Sets the template to use.

Sets the template to use.

Parameters

$file
[description]
public
# bind( string $placeholder, mixed $value )

Binds data to the template placeholders

Binds data to the template placeholders

Parameters

$placeholder
The template placeholder
$value
The value that replaced the placeholder
public
# bindStart( )

Starts a buffer that will bind data to the template placeholders. The buffer will capture anything you output until $this->bindStop()

Starts a buffer that will bind data to the template placeholders. The buffer will capture anything you output until $this->bindStop()

public
# bindStop( string $placeholder )

Stops the buffer that binds data to the template placeholders

Stops the buffer that binds data to the template placeholders

Parameters

$placeholder
The template placeholder
public mixed
# get( string $key )

Gets the data for a placeholder

Gets the data for a placeholder

Parameters

$key
$placeholder The placeholder

Returns

mixed
The data stored in the placeholder
public
# show( )

Shows the rendered template

Shows the rendered template

public
# retrieve( )

Retrieves the rendered template

Retrieves the rendered template

Properties summary
public string $extension

The extension for template files

The extension for template files

# '.tpl'
public string $directory

The template directory

The template directory

#
protected string $_file

The template file

The template file

Protected

#
protected mixed[] $_data

The data bound to the template

The data bound to the template

Protected

# array()
sleepyMUSTACHE v.0.8 API documentation generated by ApiGen