shop-old/libs/smarty/docs/programmers/api-functions/api-fetch.md
Thomas Bartelt 0a669704ea Dev-Umgebung: Kompatibilität für PHP 8.3 + Smarty 4.5.6
- Smarty 4.1.1 → 4.5.6 (behebt dynamic property deprecations)
- Core-Klassen: #[\AllowDynamicProperties] für Admin_role, base, Config,
  Customer, Customer_group, CustomerGroups, Item, Structure, website
- website.class.php: counts[parent_id] initialisieren vor ++ (PHP 8.1)
- layout.class.php: HTTP_ACCEPT_LANGUAGE mit isset-Guard
- website_init.php: session_status()-Check vor session_start
- .htaccess: HTTPS-Redirect via X-Forwarded-Proto (statt SERVER_PORT)
- themes/easyshop_advanced/media/: Parent-Theme-Assets nachgezogen
- .gitignore: smarty.4.1.1.bak ausschließen
2026-04-20 01:19:01 +02:00

1.8 KiB

fetch()

returns the template output

Description

string

fetch

string

template

string

cache_id

string

compile_id

This returns the template output instead of displaying it. Supply a valid template resource type and path. As an optional second parameter, you can pass a $cache id, see the caching section 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() 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} display(), {eval}, and templateExists().