Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Find Wedding Dresses Online at Canada from Ca-dresses.com

Find your local domestic cleaner

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Advertisement

Name

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.

As an optional third parameter, you can pass a $compile_id. This is in the event that you want to compile different versions of the same template, such as having separate templates compiled for different languages. You can also set the $compile_id variable once instead of passing this to each call to this function.

Example 14.21. fetch()


<?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;
?>

    


Example 14.22. Using fetch() to send an email

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().

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 20 plus 6? (Are you human?)

Advertisement

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
First Click Internet Marketing @fcinternetmarketing.com
Credit Card Processing Company