| 148 |
lars |
1 |
createData()
|
|
|
2 |
|
|
|
3 |
creates a data object
|
|
|
4 |
|
|
|
5 |
Description
|
|
|
6 |
===========
|
|
|
7 |
|
|
|
8 |
string
|
|
|
9 |
|
|
|
10 |
createData
|
|
|
11 |
|
|
|
12 |
object
|
|
|
13 |
|
|
|
14 |
parent
|
|
|
15 |
|
|
|
16 |
string
|
|
|
17 |
|
|
|
18 |
createData
|
|
|
19 |
|
|
|
20 |
This creates a data object which will hold assigned variables. It uses
|
|
|
21 |
the following parameters:
|
|
|
22 |
|
|
|
23 |
- `parent` is an optional parameter. It is an uplink to the main
|
|
|
24 |
Smarty object, a another user-created data object or to user-created
|
|
|
25 |
template object. These objects can be chained. Templates can access
|
|
|
26 |
variables assigned to any of the objects in it\'s parent chain.
|
|
|
27 |
|
|
|
28 |
Data objects are used to create scopes for assigned variables. They can
|
|
|
29 |
be used to control which variables are seen by which templates.
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
<?php
|
|
|
33 |
include('Smarty.class.php');
|
|
|
34 |
$smarty = new Smarty;
|
|
|
35 |
|
|
|
36 |
// create data object with its private variable scope
|
|
|
37 |
$data = $smarty->createData();
|
|
|
38 |
|
|
|
39 |
// assign variable to data scope
|
|
|
40 |
$data->assign('foo','bar');
|
|
|
41 |
|
|
|
42 |
// create template object which will use variables from data object
|
|
|
43 |
$tpl = $smarty->createTemplate('index.tpl',$data);
|
|
|
44 |
|
|
|
45 |
// display the template
|
|
|
46 |
$tpl->display();
|
|
|
47 |
?>
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
See also [`display()`](#api.display), and
|
|
|
52 |
[`createTemplate()`](#api.create.template),
|