
Comparing changes: https://github.com/smarty-php/smarty/compare/v4.3.1...v4.4.1 It is noticeable that Smarty 4.3.1 does not officially support PHP 8.3. Is only supported with 4.4.0. Remark: During tests with Smarty 4.5.1, it was noticed that the following warning occurs: Deprecated: Using the unregistered function "function_exists" in a template is deprecated and will be removed in a future version. Use Smarty::registerPlugin to explicitly register a custom modifier. As of Smarty 5.X.X, templates must be revised again. The Smarty release 5.0.2 is already officially available. However, integration into FlatPress is not entirely trivial.
92 lines
1.8 KiB
Markdown
92 lines
1.8 KiB
Markdown
fetch()
|
|
|
|
returns the template output
|
|
|
|
Description
|
|
===========
|
|
|
|
string
|
|
|
|
fetch
|
|
|
|
string
|
|
|
|
template
|
|
|
|
string
|
|
|
|
cache\_id
|
|
|
|
string
|
|
|
|
compile\_id
|
|
|
|
This returns the template output instead of [displaying](#api.display)
|
|
it. Supply a valid [template resource](#resources) type and path. As an
|
|
optional second parameter, you can pass a `$cache id`, see the [caching
|
|
section](#caching) for more information.
|
|
|
|
PARAMETER.COMPILEID
|
|
|
|
|
|
<?php
|
|
include('Smarty.class.php');
|
|
$smarty = new Smarty;
|
|
|
|
$smarty->setCaching(true);
|
|
|
|
// set a separate cache_id for each unique URL
|
|
$cache_id = md5($_SERVER['REQUEST_URI']);
|
|
|
|
// capture the output
|
|
$output = $smarty->fetch('index.tpl', $cache_id);
|
|
|
|
// do something with $output here
|
|
echo $output;
|
|
?>
|
|
|
|
|
|
|
|
The `email_body.tpl` template
|
|
|
|
|
|
Dear {$contact_info.name},
|
|
|
|
Welcome and thank you for signing up as a member of our user group.
|
|
|
|
Click on the link below to login with your user name
|
|
of '{$contact_info.username}' so you can post in our forums.
|
|
|
|
{$login_url}
|
|
|
|
List master
|
|
|
|
{textformat wrap=40}
|
|
This is some long-winded disclaimer text that would automatically get wrapped
|
|
at 40 characters. This helps make the text easier to read in mail programs that
|
|
do not wrap sentences for you.
|
|
{/textformat}
|
|
|
|
|
|
|
|
The php script using the PHP [`mail()`](https://www.php.net/function.mail)
|
|
function
|
|
|
|
|
|
<?php
|
|
|
|
// get $contact_info from db or other resource here
|
|
|
|
$smarty->assign('contact_info',$contact_info);
|
|
$smarty->assign('login_url',"http://{$_SERVER['SERVER_NAME']}/login");
|
|
|
|
mail($contact_info['email'], 'Thank You', $smarty->fetch('email_body.tpl'));
|
|
|
|
?>
|
|
|
|
|
|
|
|
See also [`{fetch}`](#language.function.fetch)
|
|
[`display()`](#api.display), [`{eval}`](#language.function.eval), and
|
|
[`templateExists()`](#api.template.exists).
|