FryPHP Hello World

Let's create our main program or controller and name the file index.php:


('error_reporting'E_ALL E_STRICT);


try {
// lets create new template object
$tpl = new FryTemplate("template.php");
// set local variable named 'string' to it
$tpl->set('string''Hello World!');
// Create Fry engine
$fry = new Fry();
// Set previously created template to Fry
// try to render everything and echo result
echo $fry->render();
} catch (
Exception $e) {
"<b>Error:</b><br/>\n" $e->getMessage() 


Now lets create a view - a new template file and name it 'template.php'


<?php echo $this->get('string'?>


In template, $this refers to Fry object, but using $this in template we get local and global variables and call FryHelpers.

Now lets open our example with a browser and we should see:

Hello World!

Deeply nested templates work just like this example, only one thing - we set one master template with Fry::setTemplate(FryTemplate), and all other nested templates with Fry::setTemplatePart('name', FryTemplate). And in templates we render parts with Fry::renderPart('name'). Example can be seen by downloading FryPHP in 'examples' directory.

More examples

More complex examples can be found by downloading FryPHP in the directory 'examples'.