The Smarty Resource

Along with the standard resource class, Tonic has another resource class that extends the standard resource class but adds integration with the Smarty templating engine.

The class loads a copy of the Smarty object allowing data to be pushed into Smarty for use within the response representation. It is mostly useful for creating representation resources that simply read a parent resources data and displays it in a particular format.

An example Smarty resource

Using the Smarty resource is easy, simply add SmartyResource as the class in the representation metadata to cause the request object to load the resource as a Smarty resource:

mimetype: text/html
class: SmartyResource
title: Hello World

<html>
	<body>
		<h1>{$this->title|escape}</h1>
	</body>
</html>

The metadata of the resource is directly accessable in Smarty as members of the $this object and other data can be made available by extending the SmartyResource and adding your own data access code.

Features

The Smarty resource provides the following Smarty related features:

Automatically assigned Smarty variables

The class assigns some Smarty variables for you:

The process modifier

A single Smarty variable modifier is also defined. The process modifier can be used to process the contents of the variable for additional Smarty markup. This is useful if you are including resource properties within your response representation but want to include dynamic Smarty variables within those properties.

mimetype: text/plain
class: SmartyResource
message: My hobby: Insisting that {$this->thing} are photoshopped.
thing: real-life objects

{$this->message|process}
Back to documentation home
Created Sep 15, 2008, last modified Jan 20, 2008