| 148 |
lars |
1 |
fetch()
|
|
|
2 |
|
|
|
3 |
returns the template output
|
|
|
4 |
|
|
|
5 |
Description
|
|
|
6 |
===========
|
|
|
7 |
|
|
|
8 |
string
|
|
|
9 |
|
|
|
10 |
fetch
|
|
|
11 |
|
|
|
12 |
string
|
|
|
13 |
|
|
|
14 |
template
|
|
|
15 |
|
|
|
16 |
string
|
|
|
17 |
|
|
|
18 |
cache\_id
|
|
|
19 |
|
|
|
20 |
string
|
|
|
21 |
|
|
|
22 |
compile\_id
|
|
|
23 |
|
|
|
24 |
This returns the template output instead of [displaying](#api.display)
|
|
|
25 |
it. Supply a valid [template resource](#resources) type and path. As an
|
|
|
26 |
optional second parameter, you can pass a `$cache id`, see the [caching
|
|
|
27 |
section](#caching) for more information.
|
|
|
28 |
|
|
|
29 |
PARAMETER.COMPILEID
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
<?php
|
|
|
33 |
include('Smarty.class.php');
|
|
|
34 |
$smarty = new Smarty;
|
|
|
35 |
|
|
|
36 |
$smarty->setCaching(true);
|
|
|
37 |
|
|
|
38 |
// set a separate cache_id for each unique URL
|
|
|
39 |
$cache_id = md5($_SERVER['REQUEST_URI']);
|
|
|
40 |
|
|
|
41 |
// capture the output
|
|
|
42 |
$output = $smarty->fetch('index.tpl', $cache_id);
|
|
|
43 |
|
|
|
44 |
// do something with $output here
|
|
|
45 |
echo $output;
|
|
|
46 |
?>
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
The `email_body.tpl` template
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
Dear {$contact_info.name},
|
|
|
54 |
|
|
|
55 |
Welcome and thank you for signing up as a member of our user group.
|
|
|
56 |
|
|
|
57 |
Click on the link below to login with your user name
|
|
|
58 |
of '{$contact_info.username}' so you can post in our forums.
|
|
|
59 |
|
|
|
60 |
{$login_url}
|
|
|
61 |
|
|
|
62 |
List master
|
|
|
63 |
|
|
|
64 |
{textformat wrap=40}
|
|
|
65 |
This is some long-winded disclaimer text that would automatically get wrapped
|
|
|
66 |
at 40 characters. This helps make the text easier to read in mail programs that
|
|
|
67 |
do not wrap sentences for you.
|
|
|
68 |
{/textformat}
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
The php script using the PHP [`mail()`](&url.php-manual;function.mail)
|
|
|
73 |
function
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
<?php
|
|
|
77 |
|
|
|
78 |
// get $contact_info from db or other resource here
|
|
|
79 |
|
|
|
80 |
$smarty->assign('contact_info',$contact_info);
|
|
|
81 |
$smarty->assign('login_url',"http://{$_SERVER['SERVER_NAME']}/login");
|
|
|
82 |
|
|
|
83 |
mail($contact_info['email'], 'Thank You', $smarty->fetch('email_body.tpl'));
|
|
|
84 |
|
|
|
85 |
?>
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
See also [`{fetch}`](#language.function.fetch)
|
|
|
90 |
[`display()`](#api.display), [`{eval}`](#language.function.eval), and
|
|
|
91 |
[`templateExists()`](#api.template.exists).
|