My favorites | Sign in
Project Logo
                
Search
for
Updated Sep 16, 2009 by erdmann.tester
UsageExamples  
How to set up a running system

Usage Examples

It is simple to set up a running system with the serpent template engine. Here are some examples which should be a good base for your own integration. For a detailed description of all parameters and methods take a look a the API.

Simple Example

This is the simplest way. It assumes that your template "base.tpl" is utf-8 encoded.

directory structure

index.php
serpent/
    source/*
templates/
    base.tpl
templates_compiled/

index.php

// init serpent
include('serpent/serpent.class.php');
$serpent = new serpent();
echo $serpent->render('base');

base.tpl

Hello World!

Advanced Example

This is a more advanced examples with many more set parameters.

directory structure as in the simple example above

index.php

// init serpent
$serpent = new serpent();
$serpent->compile_dir	= $dir.'templates_compiled/';
$serpent->force_compile = true;
$serpent->default_resource = 'file';
$serpent->default_compiler = 'serpent';
$serpent->setCharset('utf-8');

// init resource
$serpent->addPluginConfig('resource', 'file', array(
	'template_dir' => $dir.'templates/',
	'suffix' => '.tpl',
	'language' => 'de'
));

// render template with data
$vars = array('world'=>'World!');
$serpent->pass($vars);
echo $serpent->render('base');

base.tpl

Hello ~~$world~

Comment by andre.rauschenbach, Apr 04, 2009

Hinter der $serpent->addPluginConfig Anweisung fehlen zwei Klammern ));

Comment by erdmann.tester, Apr 06, 2009

Ups...:) thank you. Added.


Sign in to add a comment
Hosted by Google Code