Get Smarty

Donate

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

Advertisement

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.

Advertisement

Sponsors [info]

Sponsors