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 wedding dresses on SiteSteer.com - Best Online Wedding Dress Store

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

Name

fetch() — Retorna la salida del template

Descripción

string fetch(string template,
             string cache_id,
             string $compile_id);

Este retorna la salida del template en vez de desplegarla. Proporcionando un tipo y path valido template resource. Como un segundo parámetro opcional, usted puede pasar el identificador de cache. vea el caching section para mayor información.

Como tercer parametro opcional, usted puede pasar compile_id. Este en el caso que usted quira compilar diferentes versiones del mismo Tempalte, tal como tener separadas varios Templates compilados de diferentes lenguajes. Otro uso para compile_id es cuando usted usa mas de un $template_dir pero solo un $compile_dir. Ponga separado compile_id por cada $template_dir, de otra manera los tempate con el mismo nombre se sobre escibiran uno sobre otro. Uste puede poner también la variable $compile_id una vez en lugar de pasar esta por cada llamada a la función.

Example 13.14. fetch()


<?php
include('Smarty.class.php');
$smarty = new Smarty;

$smarty->caching = true;

// only do db calls if cache doesn't exist
if(!$smarty->is_cached('index.tpl')) {

  // dummy up some data
  $address = '245 N 50th';
  $db_data = array(
               'City' => 'Lincoln',
               'State' => 'Nebraska',
               'Zip' => '68502'
             );

  $smarty->assign('Name','Fred');
  $smarty->assign('Address',$address);
  $smarty->assign($db_data);

}

// capture the output
$output = $smarty->fetch('index.tpl');

// do something with $output here

echo $output;
?>

    


Example 13.15. Usando fetch() y enviando a un e-mail

El template email_body.tpl


Dear {$contact.name},

Welcome and thankyou for signing up as a member of our user group,

Click on the link below to login with your user name of '{$contact.login_id}'
so you can post in our forums.

http://{$smarty.server.SERVER_NAME}/index.php?page=login

List master
Some user group

{include file="email_disclaimer.tpl"}

    

El template email_disclaimer.tpl usando el modificador {textformat}.


{textformat wrap=40}
Unless you are named "{$contact.name}", you may read only the "odd numbered
words" (every other word beginning with the first) of the message above. If you have
violated that, then you hereby owe the sender 10 GBP for each even
numbered word you have read
{/textformat}

    

y el script de PHP usando la función mail()


<?php

// get contact from database eg using pear or adodb
$query  = 'select name, email, login_id from contacts where contact_id='.$contact_id;
$contact = $db->getRow($sql);
$smarty->assign('contact', $contact);

mail($contact['email'], 'Subject', $smarty->fetch('email_body.tpl'));

?>

    


Ver también {fetch} display(), {eval}, y template_exists().

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 7 plus 11? (Are you human?)

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
Buy from China @dhgate.com
First Click Internet Marketing @fcinternetmarketing.com