Skip to content
Devin Smith edited this page Feb 3, 2016 · 4 revisions

Each time a template is rendered, a new scope is created. This scope is accessible by the current template, and any template that it renders inside of it.


Single Scope

The display and render methods of View accept 2 parameters, the template filename, and an optional scope. Scope can also be accessed using Dependency Injection.

$tipsy->when('friends', function($Scope, $View) {
	$Scope->friends = ['bob','jim','katie'];
	$View->display('friends');
});

or

$tipsy->when('friends', function($View) {
	$View->display('friends', ['friends' => ['bob','jim','katie']]);
});

Multi Scope

whatever.php
$data = [
	'user' => [
		'name' => 'devin,
		'friends' => [
			'bob',
			'jim',
			'katie'
		]
	]
];
$View->display('home', $data);
home.phtml
Hello <?=$user->name?>!

<? foreach ($user->friends as $friend) : ?>
	<?=$include('friend', ['user' => $friend])?>
<? endforeach ; ?>
friend.phtml
<?=$user?>