Documentation

Everything you need to know about using Dwoo in your PHP projects.

Getting Started

Dwoo is a templating system used to make creating websites easier and more structured. Developing with Dwoo can be broken into two parts:

  • Creating, initializing, and managing the Dwoo runtime
  • Template creation and syntax

Installation

The recommended way to install Dwoo is via Composer:

composer require dwoo/dwoo

Or add it manually to your composer.json:

{
    "require": {
        "dwoo/dwoo": "^1.3"
    }
}

Requirements: PHP 5.3.0 or higher (PHP 7.x fully supported from v1.3.1+)

Basic Usage

<?php
require 'vendor/autoload.php';

$dwoo = new Dwoo\Core();

// Assign variables
$data = new Dwoo\Data();
$data->assign('name', 'World');

// Render a template file
echo $dwoo->get('template.tpl', $data);

Your template file template.tpl:

Hello {$name}!

Variables

Variables in Dwoo use the {$varname} syntax (compatible with Smarty):

{$name}              {* simple variable *}
{$user.name}         {* object/array property *}
{$array[0]}          {* array index *}
{$obj->method()}     {* method call *}

Control Blocks

If / Else

{if $condition}
    ...
{elseif $other}
    ...
{else}
    ...
{/if}

Foreach

{foreach $items as $item}
    {$item.name}
{foreachelse}
    No items.
{/foreach}

For

{for $i=0; $i<10; $i++}
    {$i}
{/for}

Template Inheritance

Base template (layout.tpl):

<html>
<body>
    {block name="content"}Default content{/block}
</body>
</html>

Child template:

{extends file="layout.tpl"}
{block name="content"}
    My page content here.
{/block}

Symfony Integration

A Symfony bundle is available:

composer require dwoo/dwoo-bundle

Register in AppKernel.php:

new Dwoo\Bundle\DwooBundle\DwooBundle()

CodeIgniter Integration

Copy the Dwoo library adapter to application/libraries/ and load it:

$this->load->library('dwoo');
$this->dwoo->display('template.tpl', $data);

Smarty Compatibility

Dwoo provides a Smarty adapter that allows you to run existing Smarty templates with minimal changes. Enable it by using the Dwoo\Adapters\Smarty\Dwoo class instead of Dwoo\Core.

$dwoo = new Dwoo\Adapters\Smarty\Dwoo();
// Drop-in Smarty replacement

Changelog

See all release notes on the blog or on GitHub Releases.