-
Notifications
You must be signed in to change notification settings - Fork 10
View Scope
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.
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']]);
});
$data = [
'user' => [
'name' => 'devin,
'friends' => [
'bob',
'jim',
'katie'
]
]
];
$View->display('home', $data);
Hello <?=$user->name?>!
<? foreach ($user->friends as $friend) : ?>
<?=$include('friend', ['user' => $friend])?>
<? endforeach ; ?>
<?=$user?>
- Home
- Getting Started
- Server Config
- Installation
- Installing Composer
- App
- Route Shorthand
- Config
- Routes
- Methods
- Controller Types
- Params & Regex
- Aliases
- Dependency Injection
- Advanced Routing
- Services
- User Defined Services
- Built in Services
- Middleware
- Views
- Templates
- Scope
- Resource
- Factory
- Looper
- Examples
- Plugins
- About